cron-router
About
Cron-router is a simple middleware for express which enables routing based on server time. This was initially written to enable a small parasitic art festival to occur on the www.safari.org.au website during the 2016 SafARI festival. The alternative programming hijacked the official website between 9pm to 9am AEST and was different based on the day of the week.
Usage:
cron-router exposes one function cronRoute which takes one argument, and array of Match objects.
Match object should look like this:
var match = match: year: /* optional, number or {from: number, to: number } */ month: /* optional, number or {from: number, to: number } */ date: /* optional, number or {from: number, to: number } */ day: /* optional number or {from: number, to: number } */ hours: /* optional number or {from: number, to: number } */ minutes: /* optional number or {from: number, to: number } */ route: /* an express Router */
Match properties (year, month, date, etc) accept either an explicit number or a range object {from: x, to: y}. CronRouter compares all the provided match values to the current server date and if equal or within the inclusive range, the request is passed to the provided express router.
example:
var express = ;var cronrouter = ; var app = ; var route_A = express;route_A;)var route_B = express;route_B;) var matches = match: day: 0 hours: from: 9 to: 24 route: route_A match: day: 1 //sub hours: from: 0 to: 8 route: route_B ; app; //if no matches it app; app;