Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
G1_ShoppingApp
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
G1_ShoppingApp
G1_ShoppingApp
Commits
b080cd46
Commit
b080cd46
authored
3 months ago
by
duyanhehe
Browse files
Options
Downloads
Patches
Plain Diff
fix config
parent
b99e0da6
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
.env.example
+1
-0
1 addition, 0 deletions
.env.example
app/backend/database.py
+1
-1
1 addition, 1 deletion
app/backend/database.py
app/backend/main.py
+1
-1
1 addition, 1 deletion
app/backend/main.py
app/core/config.py
+13
-13
13 additions, 13 deletions
app/core/config.py
with
16 additions
and
15 deletions
.env.example
+
1
−
0
View file @
b080cd46
# Copy this file to .env
APP_NAME = Shopping App
# Change to your own database
DATABASE_URL = mysql+pymysql://your_user:your_password@localhost/shopping # This template use mysql
# change your_user to your mysql username
...
...
This diff is collapsed.
Click to expand it.
app/backend/database.py
+
1
−
1
View file @
b080cd46
from
sqlmodel
import
SQLModel
,
Session
,
create_engine
from
app.core.config
import
settings
engine
=
create_engine
(
settings
.
DATABASE_URL
,
echo
=
settings
.
DEBUG
)
engine
=
create_engine
(
settings
.
database_url
,
echo
=
settings
.
debug
)
def
init_db
():
...
...
This diff is collapsed.
Click to expand it.
app/backend/main.py
+
1
−
1
View file @
b080cd46
...
...
@@ -8,7 +8,7 @@ from backend.routes import auth
from
backend.database
import
init_db
from
core.config
import
settings
app
=
FastAPI
(
title
=
"
Shopping App
"
,
version
=
"
1.0.0
"
,
debug
=
settings
.
DEBUG
)
app
=
FastAPI
(
title
=
"
Shopping App
"
,
version
=
"
1.0.0
"
,
debug
=
settings
.
debug
)
# initialize database
init_db
()
...
...
This diff is collapsed.
Click to expand it.
app/core/config.py
+
13
−
13
View file @
b080cd46
import
os
from
dotenv
import
load_dotenv
from
pathlib
import
Path
from
pydantic_settings
import
BaseSettings
,
SettingsConfigDict
# Load environment variables from .env (located outside /app/)
BASE_DIR
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)))
ENV_PATH
=
os
.
path
.
join
(
BASE_DIR
,
"
.env
"
)
load_dotenv
(
ENV_PATH
)
class
Settings
(
BaseSettings
):
app_name
:
str
=
"
Shopping App
"
database_url
:
str
# Ensure lowercase to match the .env key
secret_key
:
str
debug
:
bool
=
True
# Lowercase to match Python conventions
class
Settings
:
DATABASE_URL
:
str
=
os
.
getenv
(
"
DATABASE_URL
"
)
SECRET_KEY
:
str
=
os
.
getenv
(
"
SECRET_KEY
"
)
DEBUG
:
bool
=
os
.
getenv
(
"
DEBUG
"
,
"
False
"
).
lower
()
in
[
"
true
"
,
"
1
"
]
if
DATABASE_URL
is
None
:
raise
ValueError
(
"
DATABASE_URL is not set or empty
"
)
model_config
=
SettingsConfigDict
(
env_file
=
str
(
Path
(
__file__
).
resolve
().
parent
.
parent
/
"
.env
"
),
env_file_encoding
=
"
utf-8
"
,
case_sensitive
=
False
,
# Allows case-insensitive environment variable keys
)
# Create a singleton instance to use in the app
settings
=
Settings
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment