hashicorp / next-remote-watch

Decorated local server for next.js that enables reloads from remote data changes
Mozilla Public License 2.0
350 stars 19 forks source link

feat: support nextjs v12 #35

Closed kirill-kruchkov closed 2 years ago

kirill-kruchkov commented 2 years ago

NextJS v12 requires a hostname and port to be provided for the custom server when a middleware is used in the project (https://nextjs.org/docs/advanced-features/custom-server). Updating NextJS breaks such a project's dev server, if it uses next-remote-watch@1.0.0. Here's an example:

image

This PR updates NextJS as a devDependency (not a peerDependency) of next-remote-watch and addresses the aforementioned issue by:

  1. Reading a HOSTNAME alongside the PORT from env variables.
  2. Supplying a default value for the hostname (localhost).
  3. Providing both in the next(...) options.

It also adds a middleware to test this behaviour.

hashicorp-cla commented 2 years ago

CLA assistant check
All committers have signed the CLA.

BRKalow commented 2 years ago

Thanks for the contribution! It looks like it will, but just confirming, will this change work fine on older versions of next?

kirill-kruchkov commented 2 years ago

Hello @BRKalow! I think it should, but let me test it again in the evening.

kirill-kruchkov commented 2 years ago

@BRKalow I created a separate branch that includes this change while using Next v10. I haven't noticed anything unusual, but I'm not familiar well enough with all the test cases (there're 4 test scripts in the package.json). Would be great if someone could double check it: https://github.com/kirill-kruchkov/next-remote-watch/tree/test/next-10.

Also, I realised that this repo uses npm (I used yarn at first), so I updated this PR accordingly (dropped yarn.lock and updated package-lock.json).