import app from './server';
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;

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

if (module.hot) {
  console.log('✅  Server-side HMR Enabled!');

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

@@ -268,79 +268,93 @@
 ack%0A
-const server = http.createServer(app.callback());%0A%0Alet currentApp = app
+let currentHandler = app.callback();%0Aconst server = http.createServer(currentHandler)
 ;%0A%0As
@@ -451,11 +451,9 @@
   %7D%0A
-  
 %0A
+
   co
@@ -680,19 +680,23 @@
  current
-App
+Handler
 );%0A    c
@@ -703,19 +703,23 @@
 onst new
-App
+Handler
  = requi
@@ -740,16 +740,27 @@
 .default
+.callback()
 ;%0A    se
@@ -781,19 +781,23 @@
 st', new
-App
+Handler
 );%0A    c
@@ -806,20 +806,28 @@
 rent
-App = newApp
+Handler = newHandler
 ;%0A  

fix koa hmr (#693)