Using a Custom Express.js Server
Learn to customize any Express.js server for our application.
We'll cover the following...
We'll cover the following...
Writing a custom Express.js server to render Next.js pages is easier than we might think.
Let’s start with an index.js file inside the project root and import the required dependencies:
We now need to instantiate the Next.js app, and we can do that by adding the following code right after the import statements:
Universal URL handling
Let’s complete our server by writing the main function, which takes every incoming GET request and passes it to Next.js for server-side rendering:
Let’s focus on the main function body and see what’s going on. First of all, we wait for the Next.js app to be ready for rendering. Then, we instantiate a handle constant, which will handle the incoming ...