From 3af4fc5d67578896809bf95ba9c4f3375c1dfd62 Mon Sep 17 00:00:00 2001 From: timkim Date: Thu, 1 Dec 2016 14:21:07 -0800 Subject: [PATCH] [#184] - actually include the middleware --- lib/middleware/devmode.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 lib/middleware/devmode.js diff --git a/lib/middleware/devmode.js b/lib/middleware/devmode.js new file mode 100644 index 0000000..7c1c924 --- /dev/null +++ b/lib/middleware/devmode.js @@ -0,0 +1,35 @@ +/** + * Devmode Middleware + * + * When the new developer app registers with this middleware, it'll + * set a few things to ensure autoreload works but also turns off + * the injected scripts. In addition, it provides the appID back to + * the client that requests it. + * + * This is mostly for backwards compat. + * + * Options: + * + * - `options` {Object} + */ + +module.exports = function(options) { + // optional options parameter + options = options || {}; + + // return the appID to the client + return function(req, res, next) { + if (req.url.indexOf('/__api__/devmode') === 0) { + // set devmode to be true so as not to inject the scripts in the later middleware + options.isDevmode = true; + + res.writeHead(200, { 'Content-Type': 'text/json' }); + res.end(JSON.stringify({ + appID: options.appID + })); + } + else { + next(); + } + }; +};