Skip to content

Commit 4e6284e

Browse files
authored
improving project configuration (#25)
* delete unused email configuration * update the default env configuration file to `.env` * update log file name configuration * update alembic migration file naming style * delete the comma after the env_file variable
1 parent d6cf5d8 commit 4e6284e

File tree

5 files changed

+6
-29
lines changed

5 files changed

+6
-29
lines changed

backend/app/.env.example

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,3 @@ APS_REDIS_PASSWORD=''
1717
APS_REDIS_DATABASE=1
1818
# Token
1919
TOKEN_SECRET_KEY='1VkVF75nsNABBjK_7-qz7GtzNy3AMvktc9TCPwKczCk'
20-
# Email
21-
EMAIL_USER='xxxx-nav@qq.com'
22-
EMAIL_PASSWORD=''

backend/app/alembic.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
script_location = alembic
66

77
# template used to generate migration files
8-
# file_template = %%(rev)s_%%(slug)s
8+
file_template = %%(year)d-%%(month).2d-%%(day).2d_%%(hour).2d-%%(minute).2d_%%(rev)s_%%(slug)s
99

1010
# sys.path path, will be prepended to sys.path if present.
1111
# defaults to the current working directory.

backend/app/common/log.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from loguru import logger
99

1010
from backend.app.core import path_conf
11+
from backend.app.core.conf import settings
1112

1213

1314
class Logger:
@@ -17,7 +18,7 @@ def log() -> loguru.Logger:
1718
os.mkdir(path_conf.LogPath)
1819

1920
# 日志文件
20-
log_file = os.path.join(path_conf.LogPath, 'FastBlog.log')
21+
log_file = os.path.join(path_conf.LogPath, settings.LOG_FILE_NAME)
2122

2223
# loguru日志
2324
# more: https://github.com/Delgan/loguru#ready-to-use-out-of-the-box-without-boilerplate

backend/app/core/conf.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ class Settings(BaseSettings):
3131
# Env Token
3232
TOKEN_SECRET_KEY: str # 密钥 secrets.token_urlsafe(32))
3333

34-
# Env Email
35-
EMAIL_USER: str
36-
EMAIL_PASSWORD: str # 授权密码,非邮箱密码
37-
3834
# FastAPI
3935
TITLE: str = 'FastAPI'
4036
VERSION: str = '0.0.1'
@@ -78,14 +74,8 @@ def validator_api_url(cls, values):
7874
TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 1 # token 时效 60 * 24 * 1 = 1 天
7975
TOKEN_URL: str = '/v1/users/login'
8076

81-
# Email
82-
EMAIL_DESCRIPTION: str = 'fastapi_sqlalchemy_mysql' # 默认发件说明
83-
EMAIL_SERVER: str = 'smtp.qq.com'
84-
EMAIL_PORT: int = 465
85-
EMAIL_SSL: bool = True
86-
87-
# Cookies
88-
COOKIES_MAX_AGE: int = 60 * 5 # cookies 时效 60 * 5 = 5 分钟
77+
# Log
78+
LOG_FILE_NAME: str = 'fba.log'
8979

9080
# Middleware
9181
MIDDLEWARE_CORS: bool = True
@@ -94,7 +84,7 @@ def validator_api_url(cls, values):
9484

9585
class Config:
9686
# https://docs.pydantic.dev/usage/settings/#dotenv-env-support
97-
env_file = '.env', '.env.example'
87+
env_file = '.env'
9888
env_file_encoding = 'utf-8'
9989

10090

docker_conf.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,6 @@ class Settings(BaseSettings):
5151
TOKEN_SECRET_KEY: str = '1VkVF75nsNABBjK_7-qz7GtzNy3AMvktc9TCPwKczCk' # 密钥 secrets.token_urlsafe(32))
5252
TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 1 # token 时效 60 * 24 * 1 = 1 天
5353

54-
# Email
55-
EMAIL_DESCRIPTION: str = 'fastapi_sqlalchemy_mysql' # 默认发件说明
56-
EMAIL_SERVER: str = 'smtp.qq.com'
57-
EMAIL_PORT: int = 465
58-
EMAIL_USER: str = 'xxxx-nav@qq.com'
59-
EMAIL_PASSWORD: str = '' # 授权密码,非邮箱密码
60-
EMAIL_SSL: bool = True # 是否使用ssl
61-
62-
# 邮箱登录验证码过期时间
63-
EMAIL_LOGIN_CODE_MAX_AGE: int = 60 * 2 # 时效 60 * 2 = 2 分钟
64-
6554
# Cookies
6655
COOKIES_MAX_AGE: int = 60 * 5 # cookies 时效 60 * 5 = 5 分钟
6756

0 commit comments

Comments
 (0)