Skip to content

Commit edbbe9e

Browse files
committed
Add cors
1 parent 42489f5 commit edbbe9e

File tree

9 files changed

+439
-3
lines changed

9 files changed

+439
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
PROJECT_NAME=app
1+
PROJECT_NAME=app
2+
BACKEND_CORS_ORIGINS=["*"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
.vscode
2+
*.pyc
3+
__pycache__
4+
env3.7
5+
env3.6
6+
env
7+
dist
8+
.mypy_cache
9+
.idea
10+
site
11+
.coverage
12+
htmlcov
13+
.pytest_cache
14+
coverage.xml
15+
16+
pip-wheel-metadata/
17+
share/python-wheels/
18+
*.egg-info/
19+
.installed.cfg
20+
*.egg
21+
MANIFEST
22+
23+
# PyInstaller
24+
# Usually these files are written by a python script from a template
25+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
26+
*.manifest
27+
*.spec
28+
29+
# Installer logs
30+
pip-log.txt
31+
pip-delete-this-directory.txt
32+
33+
# Unit test / coverage reports
34+
htmlcov/
35+
.tox/
36+
.nox/
37+
.coverage
38+
.coverage.*
39+
.cache
40+
nosetests.xml
41+
coverage.xml
42+
*.cover
43+
*.py,cover
44+
.hypothesis/
45+
.pytest_cache/
46+
47+
# Translations
48+
*.mo
49+
*.pot
50+
51+
# Django stuff:
52+
*.log
53+
local_settings.py
54+
db.sqlite3
55+
db.sqlite3-journal
56+
57+
# Flask stuff:
58+
instance/
59+
.webassets-cache
60+
61+
# Scrapy stuff:
62+
.scrapy
63+
64+
# Sphinx documentation
65+
docs/_build/
66+
67+
# PyBuilder
68+
target/
69+
70+
# Jupyter Notebook
71+
.ipynb_checkpoints
72+
73+
# IPython
74+
profile_default/
75+
ipython_config.py
76+
77+
# pyenv
78+
.python-version
79+
80+
# pipenv
81+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
82+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
83+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
84+
# install all needed dependencies.
85+
#Pipfile.lock
86+
87+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
88+
__pypackages__/
89+
90+
# Celery stuff
91+
celerybeat-schedule
92+
celerybeat.pid
93+
94+
# SageMath parsed files
95+
*.sage.py
96+
97+
# Environments
98+
.env
99+
.env.production
100+
.env.development
101+
.venv
102+
env/
103+
venv/
104+
ENV/
105+
env.bak/
106+
venv.bak/
107+
108+
# Spyder project settings
109+
.spyderproject
110+
.spyproject
111+
112+
# Rope project settings
113+
.ropeproject
114+
115+
# mkdocs documentation
116+
/site
117+
118+
# mypy
119+
.mypy_cache/
120+
.dmypy.json
121+
dmypy.json
122+
123+
# Pyre type checker
124+
.pyre/
125+
126+
db_docker
127+
minio
128+
129+
.sonarqube/*
130+
.scannerwork
131+
.ruff_cache
132+
sonarqube
133+
sonarqube/extensions
134+
sonarqube/data
135+
sonarqube/logs
136+
.terraform
137+

create_fastapi_project/templates/basic/app/app/core/config.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
from pydantic_settings import BaseSettings
3+
from pydantic import AnyHttpUrl
34
from enum import Enum
45

56

@@ -11,6 +12,7 @@ class ModeEnum(str, Enum):
1112

1213
class Settings(BaseSettings):
1314
PROJECT_NAME: str = "app"
15+
BACKEND_CORS_ORIGINS: list[str] | list[AnyHttpUrl]
1416
MODE: ModeEnum = ModeEnum.development
1517
API_VERSION: str = "v1"
1618
API_V1_STR: str = f"/api/{API_VERSION}"

create_fastapi_project/templates/basic/app/app/main.py

+10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from app.api.v1.api import api_router as api_router_v1
55
from app.core.config import settings
66
from contextlib import asynccontextmanager
7+
from starlette.middleware.cors import CORSMiddleware
78

89

910
@asynccontextmanager
@@ -24,6 +25,15 @@ async def lifespan(app: FastAPI):
2425
lifespan=lifespan,
2526
)
2627

28+
# Set all CORS origins enabled
29+
if settings.BACKEND_CORS_ORIGINS:
30+
app.add_middleware(
31+
CORSMiddleware,
32+
allow_origins=[str(origin) for origin in settings.BACKEND_CORS_ORIGINS],
33+
allow_credentials=True,
34+
allow_methods=["*"],
35+
allow_headers=["*"],
36+
)
2737

2838
@app.get("/")
2939
async def root():
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
.vscode
2+
*.pyc
3+
__pycache__
4+
env3.7
5+
env3.6
6+
env
7+
dist
8+
.mypy_cache
9+
.idea
10+
site
11+
.coverage
12+
htmlcov
13+
.pytest_cache
14+
coverage.xml
15+
16+
pip-wheel-metadata/
17+
share/python-wheels/
18+
*.egg-info/
19+
.installed.cfg
20+
*.egg
21+
MANIFEST
22+
23+
# PyInstaller
24+
# Usually these files are written by a python script from a template
25+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
26+
*.manifest
27+
*.spec
28+
29+
# Installer logs
30+
pip-log.txt
31+
pip-delete-this-directory.txt
32+
33+
# Unit test / coverage reports
34+
htmlcov/
35+
.tox/
36+
.nox/
37+
.coverage
38+
.coverage.*
39+
.cache
40+
nosetests.xml
41+
coverage.xml
42+
*.cover
43+
*.py,cover
44+
.hypothesis/
45+
.pytest_cache/
46+
47+
# Translations
48+
*.mo
49+
*.pot
50+
51+
# Django stuff:
52+
*.log
53+
local_settings.py
54+
db.sqlite3
55+
db.sqlite3-journal
56+
57+
# Flask stuff:
58+
instance/
59+
.webassets-cache
60+
61+
# Scrapy stuff:
62+
.scrapy
63+
64+
# Sphinx documentation
65+
docs/_build/
66+
67+
# PyBuilder
68+
target/
69+
70+
# Jupyter Notebook
71+
.ipynb_checkpoints
72+
73+
# IPython
74+
profile_default/
75+
ipython_config.py
76+
77+
# pyenv
78+
.python-version
79+
80+
# pipenv
81+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
82+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
83+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
84+
# install all needed dependencies.
85+
#Pipfile.lock
86+
87+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
88+
__pypackages__/
89+
90+
# Celery stuff
91+
celerybeat-schedule
92+
celerybeat.pid
93+
94+
# SageMath parsed files
95+
*.sage.py
96+
97+
# Environments
98+
.env
99+
.env.production
100+
.env.development
101+
.venv
102+
env/
103+
venv/
104+
ENV/
105+
env.bak/
106+
venv.bak/
107+
108+
# Spyder project settings
109+
.spyderproject
110+
.spyproject
111+
112+
# Rope project settings
113+
.ropeproject
114+
115+
# mkdocs documentation
116+
/site
117+
118+
# mypy
119+
.mypy_cache/
120+
.dmypy.json
121+
dmypy.json
122+
123+
# Pyre type checker
124+
.pyre/
125+
126+
db_docker
127+
minio
128+
129+
.sonarqube/*
130+
.scannerwork
131+
.ruff_cache
132+
sonarqube
133+
sonarqube/extensions
134+
sonarqube/data
135+
sonarqube/logs
136+
.terraform
137+

create_fastapi_project/templates/langchain_basic/.env.example

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
PROJECT_NAME=
1+
PROJECT_NAME=app
2+
BACKEND_CORS_ORIGINS=["*"]
23
OPENAI_API_KEY=
34
UNSPLASH_API_KEY=
45
SERP_API_KEY=

0 commit comments

Comments
 (0)