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

guidingfox

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!

lsabi

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I host my API and web app on the same domain?

How can I fix this CORS issue between my website and a site of the same domain?

How can I serve my django website from multiple machines, that is how can I make it distributed?

How can I get my react app in cloud storage and app engine api to be under the same domain?

How can I make a request to my API from my UI when they are both containers running in the same task in ECS Fargate

How can i configure my nginx to make my web app be accessed by both ip and domain name?

can i embed a private file of google drive api on my website? (the file has read permission of domain the my website)

Can I build my homepage in squarespace and have custom code for rest of website on same domain

How do I serve both web pages and API Routes by using same port address and different Handle pattern

How can I consume and HTTP API in my HTTPS website

How can I verify my custom domain on firebase using GoDaddy

How can I send email with my company domain using Nodemailer?

Can I add a hostname to my website for a domain that I do not own?

How to integrate Alfresco with my website such that both share same login page?

Python/FastAPI: how can I get headers or a specific header from my backend API?

How can I open a website in my web browser using Python?

How can I implement video chat in my website using Django?

How can I tell if a visitor to my website is using incognito mode?

How can I put a login page on my website using PHP

Why can't I use a port with my website domain name?

how can i manipulate my fastapi request headers to be mutable

How can I set sub domain to show static page in my website?

I'm using the PHPMailer to my website contact page , but I faced a problem , when the message is received both sender and receiver gmail are the same?

How can I get my domain to do this?

How can I include a port in my domain?

How do I get the same formating in my email as on my website?

How can I access my nodejs web server from my local computer using the server domain name?

How can i upload my website?

How can I run markdown on my website?