This repository was archived by the owner on Mar 5, 2021. It is now read-only.

Description
Next.js comes with HMR, which is great. But it doesn't work on http://localhost:3000 yet.
It works on http://localhost:3001 though
But it would be a better developer experience to have everything working seamlessly on http://localhost:3000
- I tried to simply use
nextProxy(req, res)
but got TypeError: Cannot read property 'waitUntilReloaded' of undefined at HotReloader._callee7$ (/Users/vadorequest/dev/serverless-with-next/node_modules/next/dist/server/hot-reloader.js:658:44)
- Then, I decided to proxy requests that Express doesn't want to handle to 3001, so that Next.js app handles them. But the proxy messes up with HMR and I haven't been able to fix it:
- I tried to proxy all
/_next
by doing app.use('/_next/', proxy('http://localhost:3001/_next/'));
but then I get 404 for all js scripts like http://localhost:3000/_next/-/main.js
- I tried to proxy them all one by one but then they return HTML content instead of JS (basically the index page), ex:
app.use('/_next/-/main.js', proxy('http://localhost:3001/_next/-/main.js'));
- If you manually browse to
http://localhost:3001/_next/-/main.js
it works okay and return the actual JS file
- I tried to disable HMR by setting
dev: false
but then the Next.js app complains Could not find a valid build in the '.next' directory!
- I tried to force contentType to
text/event-stream
when proxying /_next/webpack-hmr
and it seem to work okay as long as Express doesn't catch the request first
(which is the case with GET /:level1/:level2
route), and it does display [HMR] connected
but nothing happens when a file is changed.