Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting CORS for the FastAPI server to be accessed only be the NextJS frontend #17

Open
qu8n opened this issue Apr 27, 2024 · 0 comments

Comments

@qu8n
Copy link

qu8n commented Apr 27, 2024

Is it possible to enable CORS on the FastAPI server so that only the NextJS frontend can make requests to it?

I've tried the standard way below, which didn't work. Could the fix involve modifying the Next rewrite configs?

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

app = FastAPI()

app.add_middleware(
    CORSMiddleware,
    allow_origins=['http://localhost:3000', 'https://helloworld.vercel.app'],
    allow_methods=["*"],
    allow_headers=["*"],
)

...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant