Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix koa hmr
  • Loading branch information
ambar committed Jul 5, 2018
commit e5dd0ab6f21e8c9a0faae781db6f0cd15ccad083
15 changes: 7 additions & 8 deletions examples/with-koa/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ import http from 'http';
// Use `app#callback()` method here instead of directly
// passing `app` as an argument to `createServer` (or use `app#listen()` instead)
// @see https://github.com/koajs/koa/blob/master/docs/api/index.md#appcallback
const server = http.createServer(app.callback());

let currentApp = app;
let currentHandler = app.callback();
const server = http.createServer(currentHandler);

server.listen(process.env.PORT || 3000, (error) => {
if (error) {
console.log(error)
}

console.log('🚀 started')
});

Expand All @@ -21,9 +20,9 @@ if (module.hot) {

module.hot.accept('./server', () => {
console.log('🔁 HMR Reloading `./server`...');
server.removeListener('request', currentApp);
const newApp = require('./server').default;
server.on('request', newApp);
currentApp = newApp;
server.removeListener('request', currentHandler);
const newHandler = require('./server').default.callback();
server.on('request', newHandler);
currentHandler = newHandler;
});
}