From 7a78cb1c1686c55c71e06ff441ec1b6347f42627 Mon Sep 17 00:00:00 2001 From: Diego Valdez Date: Fri, 26 May 2023 09:51:53 -0600 Subject: [PATCH] Update readme --- README.md | 66 +++++++++++++++++++++++++++++++++++++++++++--------- app/page.tsx | 2 +- 2 files changed, 56 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index f4da3c4..db04180 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,59 @@ -This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app). +

+ + +

Next.js FastAPI Starter

+ +

+ +

Simple Next.js boilerplate that uses FastAPI as the API backend.

+ +
+ +## Introduction + +This is a hybrid Next.js + Python app that uses Next.js as the frontend and FastAPI as the API backend. One great use case of this is to write Next.js apps that use Python AI libraries on the backend. + +## How It Works + +The Python/FastAPI server is mapped into to Next.js app under `/api/`. + +This is implemented using [`next.config.js` rewrites](https://github.com/digitros/nextjs-fastapi/blob/main/next.config.js) to map any request to `/api/:path*` to the FastAPI API, which is hosted in the `/api` folder. + +On localhost, the rewrite will be made to the `127.0.0.1:8000` port, which is where the FastAPI server is running. + +In production, the FastAPI server is hosted as [Python serverless functions](https://vercel.com/docs/concepts/functions/serverless-functions/runtimes/python) on Vercel. + +## Demo + +https://nextjs-fastapi-starter.vercel.app/ + +## Deploy Your Own + +You can clone & deploy it to Vercel with one click: + +[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fdigitros%2Fnextjs-fastapi%2Ftree%2Fmain) + +## Developing Locally + +You can clone & create this repo with the following command + +```bash +npx create-next-app nextjs-fastapi --example "https://github.com/digitros/nextjs-fastapi" +``` ## Getting Started -First, run the development server: +First, install the dependencies: + +```bash +npm install +# or +yarn +# or +pnpm install +``` + +Then, run the development server: ```bash npm run dev @@ -14,9 +65,7 @@ pnpm dev Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. -You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file. - -This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font. +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 `next.config.js`). ## Learn More @@ -24,11 +73,6 @@ To learn more about Next.js, take a look at the following resources: - [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. - [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. +- [FastAPI Documentation](https://fastapi.tiangolo.com/) - learn about FastAPI features and API. You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome! - -## Deploy on Vercel - -The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js. - -Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details. diff --git a/app/page.tsx b/app/page.tsx index 2fcad16..1e3f9f5 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -8,7 +8,7 @@ export default function Home() {

Get started by editing  - api/python + api/python.py