File tree 9 files changed +439
-3
lines changed
create_fastapi_project/templates
9 files changed +439
-3
lines changed Original file line number Diff line number Diff line change 1
- PROJECT_NAME = app
1
+ PROJECT_NAME = app
2
+ BACKEND_CORS_ORIGINS = ["*"]
Original file line number Diff line number Diff line change
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
+
Original file line number Diff line number Diff line change 1
1
import os
2
2
from pydantic_settings import BaseSettings
3
+ from pydantic import AnyHttpUrl
3
4
from enum import Enum
4
5
5
6
@@ -11,6 +12,7 @@ class ModeEnum(str, Enum):
11
12
12
13
class Settings (BaseSettings ):
13
14
PROJECT_NAME : str = "app"
15
+ BACKEND_CORS_ORIGINS : list [str ] | list [AnyHttpUrl ]
14
16
MODE : ModeEnum = ModeEnum .development
15
17
API_VERSION : str = "v1"
16
18
API_V1_STR : str = f"/api/{ API_VERSION } "
Original file line number Diff line number Diff line change 4
4
from app .api .v1 .api import api_router as api_router_v1
5
5
from app .core .config import settings
6
6
from contextlib import asynccontextmanager
7
+ from starlette .middleware .cors import CORSMiddleware
7
8
8
9
9
10
@asynccontextmanager
@@ -24,6 +25,15 @@ async def lifespan(app: FastAPI):
24
25
lifespan = lifespan ,
25
26
)
26
27
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
+ )
27
37
28
38
@app .get ("/" )
29
39
async def root ():
Original file line number Diff line number Diff line change
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
+
Original file line number Diff line number Diff line change 1
- PROJECT_NAME =
1
+ PROJECT_NAME = app
2
+ BACKEND_CORS_ORIGINS = ["*"]
2
3
OPENAI_API_KEY =
3
4
UNSPLASH_API_KEY =
4
5
SERP_API_KEY =
You can’t perform that action at this time.
0 commit comments