samedi 31 octobre 2020

How to use FastApi with ready-made front-end?

I've already have ready-made front-end with HTML, JavaScript and CSS files, and I can't change them because they generates by Webpack. And I also need a backend on Python for POST requests.

I can't use FastApi to get files like HTML, JavaScript, etc., because as written in documentation the path to these file must be similar to this:

<link href="" rel="stylesheet">

And as I said, files generates by Webpack, it can't write links in this way.

I also could use FastApi as separate server, for example at http://localhost:8000, but this way all my request are blocking by Google Chrome. Even if I use FastApi's middleware:

app = FastAPI()

app.add_middleware(
    CORSMiddleware,
    allow_origins=[
        "http://localhost",
        "http://localhost:8000",
    ],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

So how can I integrate FastApi and front-end?




Aucun commentaire:

Enregistrer un commentaire