Skip to content
Snippets Groups Projects
Commit 2d16c68b authored by Tobias Ullerich's avatar Tobias Ullerich
Browse files

Add cors settings

parent eca20d8d
No related branches found
No related tags found
No related merge requests found
......@@ -5,7 +5,10 @@
"secret": "",
"useSSL": false,
"keyfile": "",
"certfile": ""
"certfile": "",
"cors_origins": [
"http://localhost:8080"
]
},
"database": {
"databasePath": "storageLeaf.db",
......
......@@ -4,6 +4,7 @@ import os
import uvicorn
from TheCodeLabs_BaseUtils.DefaultLogger import DefaultLogger
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from starlette.responses import RedirectResponse, FileResponse
from Settings import SETTINGS
......@@ -29,6 +30,15 @@ app = FastAPI(title=Constants.APP_NAME,
description='The StorageLeaf API',
servers=[{'url': SETTINGS['api']['url'], 'description': f'{Constants.APP_NAME} API'}])
if 'cors_origins' in SETTINGS['server']:
app.add_middleware(
CORSMiddleware,
allow_origins=SETTINGS['server']['cors_origins'],
allow_credentials=True,
allow_methods=['*'],
allow_headers=['*'],
)
@app.get('/', include_in_schema=False)
async def root():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment