mod_rewrite with remote config middleware
Middleware to configure an instance of connect-modrewrite which, it turn, rewrites URLs based on this configuration.
- Comes pre-packaged with a rules snapshot, but should be configured to fetch a more up-to-date instance of the rules from a server.
- Rules are cached to local disk.
- The cache-control header of the resource at rulesURL is respected; including the ability to serve stale instances of the rule if problems occur downloading a new instance.
Usage
var opts {
"rulesURL": "http://s3-eu-west-1.amazonaws.com/mod-rewrite-dev/mod-rewrite-test.conf",
"preventFallbackToPrepackagedRules": false,
"logger": winston
};
var modRewriteMiddleware = require('mrp-mod-rewrite').createRewriteMiddleware(opts);
app.use(modRewriteMiddleware);
Important
- The resource at rulesURL must be returned with a MIME type ("content-type" header) of "text/plain"
- The resource at rulesURL should be returned with a "cache-control" header that includes a "max-age" and a "stale-while-revalidate" directive
- If a "cache-control" header is not returned, defaults to 10 mins max age and 7-day stale
TODO
- Timeouts for HTTP connection
- Review performance of localstorage implementation. Consider in-memory alternative
- Consider connection pool, circuit breaker and retry policy for HTTP requests