You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### Description
Update Next.js + Flask example to use Services
### Demo URL
<!--
Provide a URL to a live deployment where we can test your PR. If a demo
isn't possible feel free to omit this section.
-->
### Type of Change
- [ ] New Example
- [x] Example updates (Bug fixes, new features, etc.)
- [ ] Other (changes to the codebase, but not to examples)
### New Example Checklist
- [ ] 🛫 `npm run new-example` was used to create the example
- [ ] 📚 The template wasn't used but I carefuly read the [Adding a new
example](https://github.com/vercel/examples#adding-a-new-example) steps
and implemented them in the example
- [ ] 📱 Is it responsive? Are mobile and tablets considered?
Copy file name to clipboardExpand all lines: python/nextjs-flask/README.md
+10-20Lines changed: 10 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,13 +15,13 @@ This is a hybrid Next.js + Python app that uses Next.js as the frontend and Flas
15
15
16
16
## How It Works
17
17
18
-
The Python/Flask server is mapped into to Next.js app under `/api/`.
18
+
This project uses [Vercel Services](https://vercel.com/docs/services)to deploy a Next.js frontend and a Flask backend as part of a single Vercel project. Services are configured in `vercel.json` using the `experimentalServices` key:
19
19
20
-
This is implemented using [`next.config.js` rewrites](https://github.com/vercel/examples/blob/main/python/nextjs-flask/next.config.js) to map any request to `/api/:path*` to the Flask API, which is hosted in the `/api` folder.
20
+
-**Frontend** — Next.js, mounted at `/`
21
+
-**Backend** — Flask, mounted at `/api/python`
21
22
22
-
On localhost, the rewrite will be made to the `127.0.0.1:5328` port, which is where the Flask server is running.
23
-
24
-
In production, the Flask server is hosted as [Python serverless functions](https://vercel.com/docs/concepts/functions/serverless-functions/runtimes/python) on Vercel.
23
+
Vercel automatically routes requests to the correct service based on the URL path prefix. It also automatically injects environment variables based on the service name to easily route between services.
24
+
To make requests to the Python backend service and keep preview environments in sync without having to hard-code urls, `NEXT_PUBLIC_BACKEND_URL` is automatically set.
25
25
26
26
## Demo
27
27
@@ -53,26 +53,16 @@ yarn
53
53
pnpm install
54
54
```
55
55
56
-
Then, run the development server:
56
+
Then, run both services locally:
57
57
58
58
```bash
59
-
npm run dev
60
-
# or
61
-
yarn dev
62
-
# or
63
-
pnpm dev
59
+
vercel dev -L
64
60
```
65
61
66
-
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
67
-
68
-
The Flask server will be running on [http://127.0.0.1:5328](http://127.0.0.1:5328) – feel free to change the port in `package.json` (you'll also need to update it in `next.config.js`).
62
+
The `-L` flag runs all services together locally without authenticating with the Vercel Cloud. Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
69
63
70
64
## Learn More
71
65
72
-
To learn more about Next.js, take a look at the following resources:
73
-
66
+
-[Vercel Services](https://vercel.com/docs/services) - learn how services work on Vercel.
74
67
-[Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
75
-
-[Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
76
-
-[Flask Documentation](https://flask.palletsprojects.com/en/1.1.x/) - learn about Flask features and API.
77
-
78
-
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
68
+
-[Flask Documentation](https://flask.palletsprojects.com/) - learn about Flask features and API.
0 commit comments