This is going to be another short technical post. As I mentioned previously, I’ve been coming up to speed on a set of new technologies in preparation for a new job (more on this soon!). I started building a site in NextJS, and have since decided that:
- I do not like the NextJS framework very much (or possibly I just don’t like frameworks), and as such:
- I would like to build a server that is not connected to my front-end
Normally, I would build a server in my technologies of choice (Node / Express), but as my new job is going to involve Golang and gRPC, I decided to ignore my own advice (to build both front-end and backend with the same technology to reduce complexity) and have started to rebuild the server in Go.
Now, I’m starting to have some feelings about Go, but without getting into that, the important thing in the short term has been to handle session management identically in both the old and new servers. And for that, I’ve needed both of them to be on the same domain (otherwise, you get all kinds of CORS and cookie issues that you won’t see in production). So I cooked up a quick little nginx configuration, got it running, and voilá! Everyone happily running on localhost:8000.
One thing I’d mention is that it was dramatically easier to set up nginx than I remember. And if you know anything about nginx, you’re going to look at what I’ve done and be incredibly disappointed. There’s really nothing exciting here. Which is fine! I was looking to build something functional, not impressive.
This configuration does the following:
- Listens for incoming traffic on localhost:8000
- Serves that traffic to 3001 (if the new API) or 3000 (if anything else)
- Serves websocket traffic to port 3000 (to handle NextJS hot-reloads)
That’s it, but as the Bard put it, ’tis enough, ’twill serve. Here’s the link: https://github.com/danscratch/nginx-basic-config
Happy coding!