vercel / next.js

The React Framework
https://nextjs.org
MIT License
127.44k stars 27.04k forks source link

Flask + NextJs works locally but Flask api do not work on Vercel #66550

Open arnaud0617 opened 5 months ago

arnaud0617 commented 5 months ago

Link to the code that reproduces this issue

https://github.com/arnaud0617/nextjs-boilerplate

To Reproduce

  1. I deployed the NexJS-boilerplate on vercel : it works

  2. I added flask and it works locally http://localhost:3000/api/hello > return the right message "Hello! This is Arnaud, from Flask"

  3. I uploaded in Vercel and get the error "https://****-projects.vercel.app/" is still working "https://***-projects.vercel.app/api/hello" is not working

I get the following error 404: NOT_FOUND Code: DNS_HOSTNAME_RESOLVED_PRIVATE ID: sfo1::n8s7h-1717543156736-e703ce3d0392

index.py from flask import Flask app = Flask(name)

@app.route('/api/hello', methods=['GET']) def hello_world(): return "Hello! This is Arnaud, from Flask"

if name == 'main': app.run(debug=True, port=5328)

next.config.js module.exports = { async rewrites() { return [ { source: '/api/:path', destination: 'http://localhost:5328/api/:path', // Proxy to Backend }, ] }, }

requirements.txt Flask==3.0.3

Current vs. Expected behavior

  1. I deployed the NexJS-boilerplate on vercel : it works

  2. I added flask and it works locally http://localhost:3000/api/hello > return the right message "Hello! This is Arnaud, from Flask"

  3. I uploaded in Vercel and I does not work. I get the error 404: NOT_FOUND Code: DNS_HOSTNAME_RESOLVED_PRIVATE ID: sfo1::n8s7h-1717543156736-e703ce3d0392

index.py from flask import Flask app = Flask(name)

@app.route('/api/hello', methods=['GET']) def hello_world(): return "Hello! This is Arnaud, from Flask"

if name == 'main': app.run(debug=True, port=5328)

next.config.js module.exports = { async rewrites() { return [ { source: '/api/:path', destination: 'http://localhost:5328/api/:path', // Proxy to Backend }, ] }, }

requirements.txt Flask==3.0.3

Provide environment information

npx --no-install next info

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Pro
  Available memory (MB): 16245
  Available CPU cores: 8
Binaries:
  Node: 20.13.1
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 14.2.3 // Latest available version is detected (14.2.3).
  eslint-config-next: 14.2.3
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.4.5
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Not sure, create-next-app, Script (next/script)

Which stage(s) are affected? (Select all that apply)

Vercel (Deployed)

Additional context

No response

kp2zf commented 5 months ago

I have this same issue, anyone?

Edit by maintainer bot: Comment was automatically minimized because it was considered unhelpful. (If you think this was by mistake, let us know). Please only comment if it adds context to the issue. If you want to express that you have the same problem, use the upvote 👍 on the issue description or subscribe to the issue for updates. Thanks!

alexburciu commented 3 months ago

This example is also outdated and might require fixing: https://github.com/vercel/examples/blob/main/python/nextjs-flask/next.config.js