From 42489f56a27523243df26115f65431c47b48b76a Mon Sep 17 00:00:00 2001 From: PyPI Poetry Publish Bot Date: Thu, 31 Aug 2023 21:24:20 +0000 Subject: [PATCH 1/3] Change version to 0.1.8 From 670a2a676075bd57fa05ed1f6a9f9f306e712e04 Mon Sep 17 00:00:00 2001 From: PyPI Poetry Publish Bot Date: Thu, 31 Aug 2023 21:28:00 +0000 Subject: [PATCH 2/3] Change version to 0.2.0 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 0857936..bb6bea8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "create-fastapi-project" -version = "0.1.8" +version = "0.2.0" description = "" authors = ["jonra1993 "] readme = "README.md" From edbbe9e91c9e82ec0e6f1d81d87a39a33c21515c Mon Sep 17 00:00:00 2001 From: jonra1993 Date: Thu, 7 Sep 2023 15:26:55 -0500 Subject: [PATCH 3/3] Add cors --- .../templates/basic/.env.example | 3 +- .../templates/basic/.gitignore | 137 ++++++++++++++++++ .../templates/basic/app/app/core/config.py | 2 + .../templates/basic/app/app/main.py | 10 ++ .../templates/full/.gitignore | 137 ++++++++++++++++++ .../templates/langchain_basic/.env.example | 3 +- .../templates/langchain_basic/.gitignore | 137 ++++++++++++++++++ .../backend/app/app/core/config.py | 3 +- .../langchain_basic/backend/app/app/main.py | 10 ++ 9 files changed, 439 insertions(+), 3 deletions(-) create mode 100644 create_fastapi_project/templates/basic/.gitignore create mode 100644 create_fastapi_project/templates/full/.gitignore create mode 100644 create_fastapi_project/templates/langchain_basic/.gitignore diff --git a/create_fastapi_project/templates/basic/.env.example b/create_fastapi_project/templates/basic/.env.example index 046f2bf..ffaa5c8 100644 --- a/create_fastapi_project/templates/basic/.env.example +++ b/create_fastapi_project/templates/basic/.env.example @@ -1 +1,2 @@ -PROJECT_NAME=app \ No newline at end of file +PROJECT_NAME=app +BACKEND_CORS_ORIGINS=["*"] \ No newline at end of file diff --git a/create_fastapi_project/templates/basic/.gitignore b/create_fastapi_project/templates/basic/.gitignore new file mode 100644 index 0000000..d3e5d72 --- /dev/null +++ b/create_fastapi_project/templates/basic/.gitignore @@ -0,0 +1,137 @@ +.vscode +*.pyc +__pycache__ +env3.7 +env3.6 +env +dist +.mypy_cache +.idea +site +.coverage +htmlcov +.pytest_cache +coverage.xml + +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.env.production +.env.development +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +db_docker +minio + +.sonarqube/* +.scannerwork +.ruff_cache +sonarqube +sonarqube/extensions +sonarqube/data +sonarqube/logs +.terraform + diff --git a/create_fastapi_project/templates/basic/app/app/core/config.py b/create_fastapi_project/templates/basic/app/app/core/config.py index 33822b4..42525a7 100644 --- a/create_fastapi_project/templates/basic/app/app/core/config.py +++ b/create_fastapi_project/templates/basic/app/app/core/config.py @@ -1,5 +1,6 @@ import os from pydantic_settings import BaseSettings +from pydantic import AnyHttpUrl from enum import Enum @@ -11,6 +12,7 @@ class ModeEnum(str, Enum): class Settings(BaseSettings): PROJECT_NAME: str = "app" + BACKEND_CORS_ORIGINS: list[str] | list[AnyHttpUrl] MODE: ModeEnum = ModeEnum.development API_VERSION: str = "v1" API_V1_STR: str = f"/api/{API_VERSION}" diff --git a/create_fastapi_project/templates/basic/app/app/main.py b/create_fastapi_project/templates/basic/app/app/main.py index b8956ff..6164006 100644 --- a/create_fastapi_project/templates/basic/app/app/main.py +++ b/create_fastapi_project/templates/basic/app/app/main.py @@ -4,6 +4,7 @@ from app.api.v1.api import api_router as api_router_v1 from app.core.config import settings from contextlib import asynccontextmanager +from starlette.middleware.cors import CORSMiddleware @asynccontextmanager @@ -24,6 +25,15 @@ async def lifespan(app: FastAPI): lifespan=lifespan, ) +# Set all CORS origins enabled +if settings.BACKEND_CORS_ORIGINS: + app.add_middleware( + CORSMiddleware, + allow_origins=[str(origin) for origin in settings.BACKEND_CORS_ORIGINS], + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], + ) @app.get("/") async def root(): diff --git a/create_fastapi_project/templates/full/.gitignore b/create_fastapi_project/templates/full/.gitignore new file mode 100644 index 0000000..d3e5d72 --- /dev/null +++ b/create_fastapi_project/templates/full/.gitignore @@ -0,0 +1,137 @@ +.vscode +*.pyc +__pycache__ +env3.7 +env3.6 +env +dist +.mypy_cache +.idea +site +.coverage +htmlcov +.pytest_cache +coverage.xml + +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.env.production +.env.development +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +db_docker +minio + +.sonarqube/* +.scannerwork +.ruff_cache +sonarqube +sonarqube/extensions +sonarqube/data +sonarqube/logs +.terraform + diff --git a/create_fastapi_project/templates/langchain_basic/.env.example b/create_fastapi_project/templates/langchain_basic/.env.example index c50d353..e94d7ef 100644 --- a/create_fastapi_project/templates/langchain_basic/.env.example +++ b/create_fastapi_project/templates/langchain_basic/.env.example @@ -1,4 +1,5 @@ -PROJECT_NAME= +PROJECT_NAME=app +BACKEND_CORS_ORIGINS=["*"] OPENAI_API_KEY= UNSPLASH_API_KEY= SERP_API_KEY= diff --git a/create_fastapi_project/templates/langchain_basic/.gitignore b/create_fastapi_project/templates/langchain_basic/.gitignore new file mode 100644 index 0000000..d3e5d72 --- /dev/null +++ b/create_fastapi_project/templates/langchain_basic/.gitignore @@ -0,0 +1,137 @@ +.vscode +*.pyc +__pycache__ +env3.7 +env3.6 +env +dist +.mypy_cache +.idea +site +.coverage +htmlcov +.pytest_cache +coverage.xml + +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.env.production +.env.development +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +db_docker +minio + +.sonarqube/* +.scannerwork +.ruff_cache +sonarqube +sonarqube/extensions +sonarqube/data +sonarqube/logs +.terraform + diff --git a/create_fastapi_project/templates/langchain_basic/backend/app/app/core/config.py b/create_fastapi_project/templates/langchain_basic/backend/app/app/core/config.py index 9c5c723..c660ac9 100644 --- a/create_fastapi_project/templates/langchain_basic/backend/app/app/core/config.py +++ b/create_fastapi_project/templates/langchain_basic/backend/app/app/core/config.py @@ -1,5 +1,5 @@ import os -from pydantic import BaseSettings +from pydantic import AnyHttpUrl, BaseSettings from enum import Enum @@ -11,6 +11,7 @@ class ModeEnum(str, Enum): class Settings(BaseSettings): PROJECT_NAME: str = "app" + BACKEND_CORS_ORIGINS: list[str] | list[AnyHttpUrl] MODE: ModeEnum = ModeEnum.development API_VERSION: str = "v1" API_V1_STR: str = f"/api/{API_VERSION}" diff --git a/create_fastapi_project/templates/langchain_basic/backend/app/app/main.py b/create_fastapi_project/templates/langchain_basic/backend/app/app/main.py index cf488fc..da80a52 100644 --- a/create_fastapi_project/templates/langchain_basic/backend/app/app/main.py +++ b/create_fastapi_project/templates/langchain_basic/backend/app/app/main.py @@ -4,6 +4,7 @@ from app.core.config import settings from app.templates.chat import chat_html from contextlib import asynccontextmanager +from starlette.middleware.cors import CORSMiddleware @asynccontextmanager @@ -23,6 +24,15 @@ async def lifespan(app: FastAPI): lifespan=lifespan, ) +# Set all CORS origins enabled +if settings.BACKEND_CORS_ORIGINS: + app.add_middleware( + CORSMiddleware, + allow_origins=[str(origin) for origin in settings.BACKEND_CORS_ORIGINS], + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], + ) @app.get("/") async def root():