|
| 1 | +<p align="center"> |
| 2 | + <a href="https://nuxtjs-fastapi-starter.vercel.app/"> |
| 3 | + <img src="https://assets.vercel.com/image/upload/v1588805858/repositories/vercel/logo.png" height="96"> |
| 4 | + <h3 align="center">Nuxt.js FastAPI Starter</h3> |
| 5 | + </a> |
| 6 | +</p> |
| 7 | + |
| 8 | +<p align="center">Simple Nuxt.js boilerplate that uses <a href="https://fastapi.tiangolo.com/">FastAPI</a> as the API backend.</p> |
| 9 | + |
| 10 | +<br/> |
| 11 | + |
| 12 | +## Introduction |
| 13 | + |
| 14 | +This is a hybrid Nuxt.js + Python app that uses Nuxt.js as the frontend and FastAPI as the API backend. One great use case of this is to write Nuxt.js apps that use Python AI libraries on the backend. |
| 15 | + |
| 16 | +## How It Works |
| 17 | + |
| 18 | +The Python/FastAPI server is mapped into to Nuxt.js app under `/api/`. |
| 19 | + |
| 20 | +The server API of Nuxt3 has been relocated to `/backend/` to make it compatible with the Vercel API routes. |
| 21 | + |
| 22 | +This is implemented using [`nuxt.config.js` rewrites](https://github.com/tutorfx/nuxtjs-fastapi/blob/main/nuxt.config.ts) to map any request to `/api/:path*` to the FastAPI API, which is hosted in the `/api` folder. |
| 23 | + |
| 24 | +On localhost, the rewrite will be made to the `127.0.0.1:8000` port, which is where the FastAPI server is running. |
| 25 | + |
| 26 | +In production, the FastAPI server is hosted as [Python serverless functions](https://vercel.com/docs/concepts/functions/serverless-functions/runtimes/python) on Vercel. |
| 27 | + |
| 28 | +## Demo |
| 29 | + |
| 30 | +https://nuxtjs-fastapi-starter.vercel.app/ |
| 31 | + |
| 32 | +## Deploy Your Own |
| 33 | + |
| 34 | +You can clone & deploy it to Vercel with one click: |
| 35 | + |
| 36 | +[](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Ftutorfx%2Fnuxtjs-fastapi%2Ftree%2Fmain) |
| 37 | + |
| 38 | +## Developing Locally |
| 39 | + |
| 40 | +You can clone & create this repo with the following command |
| 41 | + |
| 42 | +```bash |
| 43 | +npx create-nuxt-app nuxtjs-fastapi --example "https://github.com/tutorfx/nuxtjs-fastapi" |
| 44 | +``` |
| 45 | + |
| 46 | +## Getting Started |
| 47 | + |
| 48 | +First, install the dependencies: |
| 49 | + |
| 50 | +```bash |
| 51 | +npm install |
| 52 | +# or |
| 53 | +yarn |
| 54 | +# or |
| 55 | +pnpm install |
| 56 | +``` |
| 57 | + |
| 58 | +Then, run the development server: |
| 59 | + |
| 60 | +```bash |
| 61 | +npm run dev |
| 62 | +# or |
| 63 | +yarn dev |
| 64 | +# or |
| 65 | +pnpm dev |
| 66 | +``` |
| 67 | + |
| 68 | +Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. |
| 69 | + |
| 70 | +The FastApi server will be running on [http://127.0.0.1:8000](http://127.0.0.1:8000) – feel free to change the port in `package.json` (you'll also need to update it in `nuxt.config.js`). |
| 71 | + |
| 72 | +## Learn More |
| 73 | + |
| 74 | +To learn more about Nuxt.js, take a look at the following resources: |
| 75 | + |
| 76 | +- [Nuxt.js Documentation](https://nuxt.com/docs) - learn about Nuxt.js features and API. |
| 77 | +- [FastAPI Documentation](https://fastapi.tiangolo.com/) - learn about FastAPI features and API. |
| 78 | + |
| 79 | +You can check out [the Nuxt.js GitHub repository](https://github.com/nuxt/nuxt.js/) - your feedback and contributions are welcome! |
0 commit comments