Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next.js & Now – enable express server in Next.js does not work when deployed to Now #8565

Closed
kktam opened this issue Aug 29, 2019 · 6 comments
Milestone

Comments

@kktam
Copy link

kktam commented Aug 29, 2019

Bug report

Describe the bug

When a Next.js app is configured to use Express server, the application will work in localhost, but when it is deployed to now, the Express server route fails.

A clear and concise description of what the bug is.

To Reproduce

Configure the Next.js project as follows:

now.json

{
    "version": 1,
    "name": "App",
    "builds": [
        {
            "src": "package.json",
            "use": "@now/next"
        }
    ]
}

In the package.json it contains the following script

{
  "dependencies": {
    "@zeit/next-css": "^1.0.1",
    "@zeit/next-sass": "^1.0.1",
    "bootstrap": "^4.3.1",
    "express": "^4.17.1",
    "js-cookie": "^2.2.0",
    "jwt-decode": "^2.2.0",
    "next": "^9.0.3",
    "node-sass": "^4.12.0",
    "now": "^16.1.1",
    "react": "^16.8.6",
    "react-bootstrap": "^1.0.0-beta.11",
    "react-dom": "^16.8.6",
    "recompose": "^0.30.0"

...
  },
  "scripts": {
    "dev": "node server.js",
    "build": "next build",
    "now-build": "next build",
    "start": "NODE_ENV=production node server.js"
  }
}

Steps to reproduce the behavior, please provide code snippets or a repository:

Any Next.js project build with this configuration will work in localhost, but when deployed to now, the Express server routes will stop working.

Expected behavior

Expected a Next.js deployed to Zeit Now can use the Express server as SSR.
Zeit document link https://zeit.co/guides/custom-next-js-server-to-routes/?query=express#the-old-custom-server-method

Screenshots

If applicable, add screenshots to help explain your problem.

System information

  • OS: [e.g. macOS, Windows] - Tested in Windows 10 and 10/Pro
  • Browser (if applies) [e.g. chrome, safari] - IE, Edge, Chrome
  • Version of Next.js: [e.g. 6.0.2] - 9.0.3

Additional context

Add any other context about the problem here.

@Timer
Copy link
Member

Timer commented Sep 1, 2019

Sorry the guide didn't make this clear: an Express custom server is not supported on Now.

Can you please share your custom server? You may not need it.

@Timer Timer added this to the 9.0.6 milestone Sep 1, 2019
@samyilias

This comment has been minimized.

@kktam
Copy link
Author

kktam commented Sep 8, 2019

One of the example I intended to use in my application is to integrate with Auth0. On the Auth0 official website, they posted this tutorial to integrate Auth0 to use them as authentication for Next.js projects. They make heavy use of custom express server in their example. Please see https://auth0.com/blog/next-js-authentication-tutorial/.

I believe the main use of custom express server here is to make use of server side component passport to authenticate and generate sessions, both something I needed.

@kktam
Copy link
Author

kktam commented Sep 8, 2019

This may be off topic, but one of the older thread talked about the importance of using server side authentication with sites like Auth0, because of difficultly of storing and hiding JWT tokens from cross site scripting attacks from client side authentication. Re: #153

@Timer
Copy link
Member

Timer commented Sep 11, 2019

Filed a issue in our docs to fix this! We have a new Auth0 example coming soon.

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 31, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants