auths
objectreturn
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps) => {
}
/*
do a quick abort for favicon
*/
if(steps.trigger.event.url.indexOf('favicon') >= 0) $end();
/*
I look for height and width (or h and w) in the URL parameters and copy them out for easier access
*/
if(steps.trigger.event.query.w) this.width = parseInt(steps.trigger.event.query.w,10);
if(steps.trigger.event.query.width) this.width = parseInt(steps.trigger.event.query.width,10);
if(steps.trigger.event.query.h) this.height = parseInt(steps.trigger.event.query.h,10);
if(steps.trigger.event.query.height) this.height = parseInt(steps.trigger.event.query.height,10);
if(!this.width) this.width = 350;
if(!this.height) this.height = 350;
auths
objectreturn
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps) => {
}
/*
I define my placeholder services
*/
this.services = [
{
name: 'placekitten',
map: 'https://placekitten.com/${w}/${h}'
},
{
name: 'placecage',
map: 'https://www.placecage.com/${w}/${h}'
},
{
name:'fillmurry',
map: 'https://www.fillmurray.com/${w}/${h}'
},
{
name:'placeholder',
map: 'https://via.placeholder.com/${w}x${h}'
},
{
name:'placedog',
map: 'https://placedog.net/${w}/${h}'
},
{
name:'placebear',
map: 'https://placebear.com/${w}/${h}'
},
{
name:'placebeard',
map: 'https://placebeard.it/${w}x${h}'
},
{
name: 'baconmockup',
map: 'https://baconmockup.com/${w}/${h}'
}
];
auths
objectreturn
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps) => {
}
getRandomInt = function(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min) + min); //The maximum is exclusive and the minimum is inclusive
}
makeTS = function(s) {
return new Function("w","h","return `"+s+"`");
}
let service = steps.defineservices.services[getRandomInt(0, steps.defineservices.services.length)];
console.log(service);
let url = makeTS(service.map)(steps.getargs.width, steps.getargs.height);
console.log(service.name, url);
await $respond({
status:302,
headers: {
Location:url
}
})