question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature Request] Next.js custom server support

See original GitHub issue

Desired Behavior

@nrwl/next would support the custom server and routing feature of Next.js. This inevitably ties in with #1895 as well.

Current Behavior

We are limited to modifying pages.

Context

nx report just returns with Project target does not exist., but:

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:9
  • Comments:24 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
toinelincommented, Jan 14, 2021

Hello 🖖

It seems Nx implemented customServerPath on Next plugins. But I can’t make it working as I always get Couldn't find a pages directory. Please create one under the project root

"serve": {
  "executor": "@nrwl/next:server",
  "options": {
    "buildTarget": "my-next-app:build",
    "dev": true,
    "customServerPath": "server.js"
  },
  "configurations": {
    "production": {
      "buildTarget": "my-next-app:build:production",
      "dev": false,
      "customServerPath": "server.js"
    }
  }
},

My server.js file is located on app/my-next-app/server.js Does anyone has encountered the same issue ?

Thanks !

EDIT : I found the solution

If you want to use customServerPath you will have to export a function taking three args (as described in this file https://github.com/nrwl/nx/blob/master/packages/next/src/builders/server/lib/custom-server.ts) in a JS file and use the first arg as a NextJS server to call getRequestHandler on it.

It could be cool to have a bit more documentation about it on this page https://nx.dev/latest/react/plugins/next/executors/server

3reactions
stramelcommented, Mar 2, 2020

@zenVentzi this feature already is in (minus TypeScript support)

Here is an example of how to implement.

https://gist.github.com/stramel/57483a68559dca2c6471b3170a28042f

Read more comments on GitHub >

github_iconTop Results From Across the Web

Advanced Features: Custom Server - Next.js
Start a Next.js app programmatically using a custom server.
Read more >
Build a server-rendered React app with Next.js and Express
Using Express with Next.js, you can: Easily build web socket features in your applications; Develop custom or extra logic for your Next.js ......
Read more >
Next.js on Netlify
Use redirects, middleware, custom headers and more to extend your Next.js ... Netlify supports Next.js internationalized routing functionality for ...
Read more >
What's New in Next.js 13 - AppSignal Blog
It supports Server Components, TypeScript, JSX, CSS, and more. As the project is in alpha state, many of the features are not yet...
Read more >
Deploying with Custom Serverless Next.js Routing - Vercel
This is an amazing feature of Next.js, however, it cannot control how the server routes to the app if the routes are not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found