Skip to content

Instantly share code, notes, and snippets.

@ingyeoking13
Created June 30, 2022 13:27
Show Gist options
  • Save ingyeoking13/8b88e618a8b963a9d3448fff4bc1ae1f to your computer and use it in GitHub Desktop.
Save ingyeoking13/8b88e618a8b963a9d3448fff4bc1ae1f to your computer and use it in GitHub Desktop.
starting fastapi
import typing
import logging
import uvicorn
from os.path import abspath
import pathlib as path
from starlette.staticfiles import StaticFiles
from fastapi import FastAPI, Request, Response
app = FastAPI(title='my-API', version='0.0.1', docs_url=None, redoc_url=None)
@app.middleware('http')
async def add_cors(request: Request, call_next):
response: Response = await call_next(request)
response.headers['Access-Control-Allow-Origin'] = '*'
return response
static_folder = abspath(path.Path(path.Path(__file__).parent.absolute() ,'..', 'static'))
app.mount("/", StaticFiles(directory="../static", html=True), name='static')
if __name__ == '__main__':
uvicorn.run("main:app",host='0.0.0.0', port=8000, reload=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment