diff --git a/backend/README.md b/backend/README.md index 89c9f46..40d8c75 100644 --- a/backend/README.md +++ b/backend/README.md @@ -1,31 +1,58 @@ -A simple guide on how to start on poetry, a simple package manager like npm but for python. +## Poetry + FastAPI -Make sure you cd into the parent backend folder when running the api. +A simple guide on how to start on poetry, a simple **package manager** like npm but for python. -------------------------------------------------------------------------------------------- +ref : +- [official docs](https://python-poetry.org/docs/) +- [medium article](https://medium.com/@caetanoog/start-your-first-fastapi-server-with-poetry-in-10-minutes-fef90e9604d9) + +### Setup + +Make sure you `cd` into the parent backend folder when running the api. + +----------------------------------------- To start with Poetry on mac, run: -brew install poetry +`brew install poetry` + +(or) Linux, macOS, Windows (WSL) : + +`curl -sSL https://install.python-poetry.org | python3 -` -This will set up poetry. +This will set up poetry. check installation using `poetry --version` -------------------------------------------------------------------------------------------- +------------------------------------------ To install dependencies, run: -poetry install +`poetry install` + +- The install command reads the `pyproject.toml` file from the current project, resolves the dependencies, and installs them. +- If there is a `poetry.lock` file in the current directory, it will use the exact versions from there instead of resolving them. +- This ensures that everyone using the library will get the same versions of the dependencies. + +------------------------------------------ + + +To start the FastAPI server locally (using virtual env), run: -------------------------------------------------------------------------------------------- +`poetry shell` +and then run: -To start the api locally, run: +`uvicorn main:app --reload` -poetry shell +- Your local host on port `8000` should now be running the api : http://127.0.0.1:8000/ -AND THEN: +### Frontend: basic request to API -uvicorn main:app --reload +ref : +- guide : https://vercel.com/templates/next.js/nextjs-fastapi-starter +- repo : https://github.com/digitros/nextjs-fastapi + > Make sure both the frontend and backend setups are up and running -Your local host on port 8000 should now be running the api \ No newline at end of file +- next.js frontend running on http://localhost:3000/ +- fastAPI server runs on http://127.0.0.1:8000/ +- front end api requests made from http://localhost:3000/api/python diff --git a/backend/main.py b/backend/main.py index d786432..a6d81bc 100644 --- a/backend/main.py +++ b/backend/main.py @@ -2,7 +2,10 @@ app = FastAPI() - @app.get("/") async def root(): - return {"message": "Hello World"} \ No newline at end of file + return {"message": "Hello World"} + +@app.get("/api/python") +async def root(): + return {"message": "Hello from fastAPI backend"} \ No newline at end of file diff --git a/frontend/next.config.js b/frontend/next.config.js index a843cbe..f8a3f5f 100644 --- a/frontend/next.config.js +++ b/frontend/next.config.js @@ -1,6 +1,30 @@ /** @type {import('next').NextConfig} */ const nextConfig = { - reactStrictMode: true, -} + rewrites: async () => { + return [ + { + source: "/api/:path*", + destination: + process.env.NODE_ENV === "development" + ? "http://127.0.0.1:8000/api/:path*" + : "/api/", + }, + { + source: "/docs", + destination: + process.env.NODE_ENV === "development" + ? "http://127.0.0.1:8000/docs" + : "/api/docs", + }, + { + source: "/openapi.json", + destination: + process.env.NODE_ENV === "development" + ? "http://127.0.0.1:8000/openapi.json" + : "/api/openapi.json", + }, + ]; + }, +}; -module.exports = nextConfig +module.exports = nextConfig; \ No newline at end of file diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 61a265f..4ab3186 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -12,7 +12,7 @@ "@emotion/styled": "^11.11.0", "@mui/icons-material": "^5.14.14", "@mui/material": "^5.14.14", - "next": "13.5.6", + "next": "^13.5.6", "react": "^18", "react-dom": "^18", "sass": "^1.69.4" diff --git a/frontend/src/pages/index.js b/frontend/src/pages/index.js index 372c3df..1741d60 100644 --- a/frontend/src/pages/index.js +++ b/frontend/src/pages/index.js @@ -1,3 +1,5 @@ export default function Home() { - return

; + return

+ Hello Team! +

; }