Skip to content

Commit 72934d9

Browse files
ambarjaredpalmer
authored andcommitted
fix koa hmr (#693)
1 parent 8a35624 commit 72934d9

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

examples/with-koa/src/index.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ import http from 'http';
44
// Use `app#callback()` method here instead of directly
55
// passing `app` as an argument to `createServer` (or use `app#listen()` instead)
66
// @see https://github.com/koajs/koa/blob/master/docs/api/index.md#appcallback
7-
const server = http.createServer(app.callback());
8-
9-
let currentApp = app;
7+
let currentHandler = app.callback();
8+
const server = http.createServer(currentHandler);
109

1110
server.listen(process.env.PORT || 3000, (error) => {
1211
if (error) {
1312
console.log(error)
1413
}
15-
14+
1615
console.log('🚀 started')
1716
});
1817

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

2221
module.hot.accept('./server', () => {
2322
console.log('🔁 HMR Reloading `./server`...');
24-
server.removeListener('request', currentApp);
25-
const newApp = require('./server').default;
26-
server.on('request', newApp);
27-
currentApp = newApp;
23+
server.removeListener('request', currentHandler);
24+
const newHandler = require('./server').default.callback();
25+
server.on('request', newHandler);
26+
currentHandler = newHandler;
2827
});
2928
}

0 commit comments

Comments
 (0)