Skip to content

Commit cae8fc8

Browse files
committed
Fusion of two domains into one : local + dev
1 parent fd557c0 commit cae8fc8

File tree

12 files changed

+70
-130
lines changed

12 files changed

+70
-130
lines changed

.github/workflows/dev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: NextShape CI - Dev
22
on:
33
push:
4-
branches: [develop]
4+
branches: [develop, fusion-domains]
55
pull_request:
66
branches: [develop]
77

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,3 +198,4 @@ dist-ssr
198198
*.sw?
199199

200200
WS/brevo.pem
201+
.env.prod

UI/Dockerfile

Lines changed: 0 additions & 26 deletions
This file was deleted.

UI/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"type": "module",
66
"scripts": {
77
"dev": "vite",
8-
"build": "vue-tsc -b && vite build",
8+
"build": "vue-tsc --noEmit && vite build",
99
"preview": "vite preview"
1010
},
1111
"dependencies": {

UI/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"paths": {
1313
"@/*": ["src/*"]
1414
},
15-
"skipLibCheck": true
15+
"skipLibCheck": true,
16+
"noEmit": true
1617
},
1718
"include": ["src", "vite.config.ts"],
1819
"exclude": ["node_modules"]

UI/vite.config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import vue from "@vitejs/plugin-vue"
33
import { fileURLToPath, URL } from "url"
44
// https://vitejs.dev/config/
55
export default defineConfig({
6-
base: "/",
6+
base: "/assets/",
7+
build: {
8+
outDir: "dist",
9+
assetsDir: "assets",
10+
},
711
plugins: [vue()],
812
resolve: {
913
alias: [

WS/Dockerfile

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,23 @@
1-
# Image Python
2-
FROM python:3.11
1+
# Étape 1 : Build Vue frontend
2+
FROM node:20 AS frontend
3+
WORKDIR /app
4+
COPY UI/ ./UI/
5+
RUN cd UI && npm install && npm run build
36

4-
# Dossier de travail
7+
# Étape 2 : Django backend avec frontend intégré
8+
FROM python:3.11
59
WORKDIR /app
610

711
RUN apt-get update && apt-get install -y postgresql-client
812

9-
# Copier et installer les dépendances
10-
COPY requirements.txt .
13+
COPY WS/requirements.txt .
1114
RUN pip install --no-cache-dir -r requirements.txt
1215

13-
# Copier le projet
14-
COPY . .
15-
COPY wait.sh .
16+
COPY WS/ .
1617

17-
# Ajouter le certificat Brevo
18-
COPY brevo.pem /usr/local/share/ca-certificates/brevo.crt
19-
RUN update-ca-certificates
18+
COPY --from=frontend /app/UI/dist /app/UI/dist
2019

21-
# Donner les droits d'exécution au script d'entrée
2220
RUN chmod +x wait.sh entrypoint.sh
2321

24-
# Exposer le port de Django
2522
EXPOSE 8000
26-
27-
# Définir le script comme point d'entrée
2823
ENTRYPOINT ["bash", "entrypoint.sh"]

WS/entrypoint.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,23 @@
22

33
echo "ENV = $ENV"
44

5+
# Check if cert is mounted and update it
6+
if [ -f /usr/local/share/ca-certificates/brevo.crt ]; then
7+
echo "Certificat brevo.pem détecté — update-ca-certificates"
8+
update-ca-certificates
9+
else
10+
echo "Aucun certificat Brevo détecté, skip"
11+
fi
12+
513
./wait.sh "$DATABASE_HOST:$DATABASE_PORT"
614

715
# Apply migrations
816
echo "Apply the migrations"
917
python manage.py migrate
1018

19+
echo "Collect static files"
20+
python manage.py collectstatic --noinput
21+
1122
if [ "$ENV" = "local" ]; then
1223
echo "Local mode (Docker local)"
1324
echo "Seeding the database..."

WS/next_shape_ws/settings.py

Lines changed: 29 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@
1414
from datetime import timedelta
1515
from pathlib import Path
1616

17-
from corsheaders.defaults import default_headers
1817
from dotenv import load_dotenv
1918

2019
# Build paths inside the project like this: BASE_DIR / 'subdir'.
21-
BASE_DIR = Path(__file__).resolve().parent.parent.parent
20+
BASE_DIR = Path(__file__).resolve().parent.parent
2221

2322
dotenv_path = BASE_DIR / ".env"
2423
load_dotenv(dotenv_path, override=True)
@@ -29,8 +28,11 @@
2928
# SECURITY WARNING: keep the secret key used in production secret!
3029
SECRET_KEY = os.getenv("DJANGO_SECRET_KEY", "fallback-secret-key-for-dev")
3130

31+
# Environment
32+
ENV = os.getenv("ENV", "local")
33+
3234
# SECURITY WARNING: don't run with debug turned on in production!
33-
DEBUG = True
35+
DEBUG = ENV == "local"
3436

3537
ALLOWED_HOSTS: list = os.getenv("DJANGO_ALLOWED_HOSTS", "localhost").split(",")
3638

@@ -45,12 +47,11 @@
4547
"django.contrib.messages",
4648
"django.contrib.staticfiles",
4749
"rest_framework",
48-
"corsheaders",
4950
"api",
5051
]
5152

5253
MIDDLEWARE = [
53-
"corsheaders.middleware.CorsMiddleware",
54+
"whitenoise.middleware.WhiteNoiseMiddleware",
5455
"django.middleware.security.SecurityMiddleware",
5556
"django.contrib.sessions.middleware.SessionMiddleware",
5657
"django.middleware.common.CommonMiddleware",
@@ -60,49 +61,13 @@
6061
"django.middleware.clickjacking.XFrameOptionsMiddleware",
6162
]
6263

63-
CORS_ALLOWED_ORIGINS = [
64-
"https://nextshape.onrender.com", # prod
65-
"https://nextshape-dev.onrender.com", # dev
66-
"http://localhost:5173",
67-
"http://127.0.0.1:5173",
68-
]
69-
70-
CORS_ALLOW_CREDENTIALS = True
71-
CORS_ALLOW_HEADERS = list(default_headers) + [
72-
"content-type",
73-
]
74-
75-
CORS_ALLOW_METHODS = [
76-
"DELETE",
77-
"GET",
78-
"OPTIONS",
79-
"PATCH",
80-
"POST",
81-
"PUT",
82-
]
83-
84-
ENV = os.getenv("ENV", "local")
85-
86-
if ENV == "local":
87-
CORS_ALLOWED_ORIGINS = [
88-
"http://localhost:5173",
89-
]
90-
91-
elif ENV == "dev":
92-
CORS_ALLOWED_ORIGINS = [
93-
"http://localhost:5173",
94-
"https://nextshape-dev.onrender.com",
95-
"https://nextshape.onrender.com", # prod front calls back dev for the current moment
96-
]
97-
elif ENV == "prod":
98-
CORS_ALLOWED_ORIGINS = ["https://nextshape.onrender.com"]
9964

10065
ROOT_URLCONF = "next_shape_ws.urls"
10166

10267
TEMPLATES = [
10368
{
10469
"BACKEND": "django.template.backends.django.DjangoTemplates",
105-
"DIRS": [],
70+
"DIRS": [os.path.join(BASE_DIR, "UI", "dist")],
10671
"APP_DIRS": True,
10772
"OPTIONS": {
10873
"context_processors": [
@@ -192,7 +157,12 @@
192157
# Static files (CSS, JavaScript, Images)
193158
# https://docs.djangoproject.com/en/5.1/howto/static-files/
194159

195-
STATIC_URL = "static/"
160+
STATIC_URL = "/assets/"
161+
MEDIA_URL = "/media/"
162+
163+
STATICFILES_DIRS = [BASE_DIR / "UI" / "dist"]
164+
STATIC_ROOT = BASE_DIR / "staticfiles"
165+
MEDIA_ROOT = BASE_DIR / "media"
196166

197167
# Default primary key field type
198168
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
@@ -201,7 +171,6 @@
201171

202172

203173
# JWT Settings
204-
205174
SIMPLE_JWT = {
206175
"ACCESS_TOKEN_LIFETIME": timedelta(minutes=30),
207176
"REFRESH_TOKEN_LIFETIME": timedelta(days=1),
@@ -210,23 +179,20 @@
210179
}
211180

212181

213-
# Default AutoField
214-
215-
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
216-
217-
218182
# Cookie settings for auth
219-
def get_cookie_settings():
220-
if ENV in ["dev", "prod"]:
221-
return {
222-
"httponly": True,
223-
"secure": True,
224-
"samesite": "None",
225-
"domain": "nextshape-backend-dev.onrender.com",
226-
"path": "/",
227-
}
228-
else:
229-
return {"httponly": True, "secure": False, "samesite": "Lax", "path": "/"}
230-
231-
232-
COOKIE_PARAMS = get_cookie_settings()
183+
COOKIE_PARAMS = {
184+
"httponly": True,
185+
"secure": not DEBUG,
186+
"samesite": "None" if not DEBUG else "Lax",
187+
"path": "/",
188+
}
189+
190+
if ENV == "local":
191+
# CORS config in local when we don't use docker,
192+
# we may need the access between back and front
193+
INSTALLED_APPS += ["corsheaders"]
194+
MIDDLEWARE.insert(0, "corsheaders.middleware.CorsMiddleware")
195+
196+
CORS_ALLOWED_ORIGINS = ["http://localhost:5173"]
197+
CORS_ALLOW_CREDENTIALS = True
198+
CSRF_TRUSTED_ORIGINS = ["http://localhost:5173"]

WS/next_shape_ws/urls.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
"""
1717
from django.contrib import admin
1818
from django.urls import include, path
19+
from django.views.generic import TemplateView
1920

2021
urlpatterns = [
2122
path("admin/", admin.site.urls),
2223
path("api/", include("api.urls")),
24+
path("", TemplateView.as_view(template_name="index.html")),
2325
]

0 commit comments

Comments
 (0)