Skip to content

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

@qu8n

Description

@qu8n

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=["*"],
)

...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions