Created
March 21, 2014 03:36
-
-
Save srgpqt/9679033 to your computer and use it in GitHub Desktop.
Koa with automatic code reload on every request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
var koa = require('koa'); | |
var app = koa(); | |
var some_random_value_initialized_on_reload = Math.floor(Math.random() * 100); | |
// ... set up application middleware ... | |
app.use(function *() { | |
this.body = some_random_value_initialized_on_reload; | |
}); | |
module.exports = app; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node --harmony | |
"use strict"; | |
var server; | |
if (process.env['KOA_RELOAD']) { | |
var http = require('http'); | |
server = http.createServer(function() { | |
for (var k in require.cache) { | |
if (require.cache.hasOwnProperty(k)) { | |
delete require.cache[k]; | |
} | |
} | |
require('./application').callback().apply(this, arguments); | |
}); | |
} | |
else { | |
server = require('./application'); | |
} | |
server.listen(4000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment