guidingfox
guidingfox

Reputation: 97

How can I serve both my website and my API on the same Domain using fastapi?

I am working on a project that involves users signing up and accessing a dashboard. For this I've written an API, but I don't know how to serve them both on the same domain and also use the API to change dashboard accordingly. the api is written in python using FastAPI and the site is currently written in vanilla JS (for prototyping). Is this possible? If so, how do I go about doing it?

Thanks in advance!

Upvotes: 0

Views: 1010

Answers (1)

lsabi
lsabi

Reputation: 4456

If your website consists of only static pages, you can store them in a folder and tell Fastapi to serve static files from that folder.

Here's the example taken from the docs

from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles

app = FastAPI()

app.mount("/static", StaticFiles(directory="static"), name="static")

https://fastapi.tiangolo.com/tutorial/static-files/?h=stat

Upvotes: 2

Related Questions