From 2fbee208e75b882cd4b53be1976f761efe441dba Mon Sep 17 00:00:00 2001 From: Thomas Fransolet Date: Mon, 7 Sep 2026 16:54:28 +0200 Subject: [PATCH] Add kApiBaseUrl constant --- Dockerfile | 21 +++++++++++++++----- lib/Screens/Auth/forgot_password_screen.dart | 2 +- lib/Screens/Auth/set_password_screen.dart | 2 +- lib/Screens/login_screen.dart | 4 ++-- lib/constants.dart | 8 ++++++++ nginx.conf | 21 ++++++++++++++++++++ 6 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 nginx.conf diff --git a/Dockerfile b/Dockerfile index f2d433b..39f74fd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,21 @@ -FROM cirrusci/flutter:3.7.0 AS build +# Flutter 3.44.0 : la version qui compile réellement ce projet. +# +# L'image précédente épinglait cirrusci/flutter:3.7.0, qui embarque Dart 2.19, +# alors que le pubspec exige `sdk: ">=3.1.0 <4.0.0"` — le `flutter pub get` +# échouait donc, et l'image n'était plus constructible. `cirrusci` n'est de +# toute façon plus publié : le dépôt maintenu est `cirruslabs`. +FROM ghcr.io/cirruslabs/flutter:3.44.0 AS build + +# ⚠️ L'URL de l'API est figée au BUILD : une image est liée à un environnement. +# Sans cet argument, elle vaut localhost:5000 et l'image déployée ne parle à rien. +# docker build --build-arg API_BASE_URL=https://api.mymuseum.be -t ... . +ARG API_BASE_URL=http://localhost:5000 + WORKDIR /app COPY . . RUN flutter pub get -RUN flutter build web - - -FROM nginx:1.21.1-alpine +RUN flutter build web --release --dart-define=API_BASE_URL=$API_BASE_URL +FROM nginx:1.27-alpine +COPY nginx.conf /etc/nginx/conf.d/default.conf COPY --from=build /app/build/web /usr/share/nginx/html diff --git a/lib/Screens/Auth/forgot_password_screen.dart b/lib/Screens/Auth/forgot_password_screen.dart index 571d8b0..6bb2419 100644 --- a/lib/Screens/Auth/forgot_password_screen.dart +++ b/lib/Screens/Auth/forgot_password_screen.dart @@ -17,7 +17,7 @@ class ForgotPasswordScreen extends StatefulWidget { } class _ForgotPasswordScreenState extends State { - final String host = "http://localhost:5000"; + final String host = kApiBaseUrl; String email = ""; bool isLoading = false; bool isSent = false; diff --git a/lib/Screens/Auth/set_password_screen.dart b/lib/Screens/Auth/set_password_screen.dart index fce5c0f..47a4bab 100644 --- a/lib/Screens/Auth/set_password_screen.dart +++ b/lib/Screens/Auth/set_password_screen.dart @@ -22,7 +22,7 @@ class SetPasswordScreen extends StatefulWidget { } class _SetPasswordScreenState extends State { - final String host = "http://localhost:5000"; + final String host = kApiBaseUrl; String newPassword = ""; bool isLoading = false; bool isDone = false; diff --git a/lib/Screens/login_screen.dart b/lib/Screens/login_screen.dart index eb47b8c..d11215d 100644 --- a/lib/Screens/login_screen.dart +++ b/lib/Screens/login_screen.dart @@ -33,7 +33,7 @@ class LoginScreen extends StatefulWidget { class _LoginScreenState extends State { String email = ""; // DEV "test@email.be" String password = ""; // DEV = "kljqsdkljqsd" - String? host = "http://localhost:5000"; // "https://api.myinfomate.be" // "https://api.mymuseum.be" // DEV = "http://192.168.31.96" // http://localhost:5000 // https://api.mymuseum.be // myCore http://192.168.31.140:8089 + String? host = kApiBaseUrl; // "https://api.myinfomate.be" // "https://api.mymuseum.be" // DEV = "http://192.168.31.96" // http://localhost:5000 // https://api.mymuseum.be // myCore http://192.168.31.140:8089 Client? clientAPI; bool isLoading = false; bool isRememberMe = false; @@ -169,7 +169,7 @@ class _LoginScreenState extends State { @override void initState() { - this.host = "http://localhost:5000"; + this.host = kApiBaseUrl; if (localStorage.containsKey("remember")) { this.isRememberMe = true; diff --git a/lib/constants.dart b/lib/constants.dart index 914e285..20dfcb8 100644 --- a/lib/constants.dart +++ b/lib/constants.dart @@ -15,6 +15,14 @@ const kWhite = Color(0xFFFFFFFF); const kBlack = Color(0xFF000000); const kSuccess = Color(0xFF8bc34a); +// URL de l'API, injectee au build : +// flutter build web --dart-define=API_BASE_URL=https://api.mymuseum.be +// +// Elle etait ecrite en dur a quatre endroits, donc une image de manager-web +// etait liee a un environnement sans que rien ne le signale. +const kApiBaseUrl = String.fromEnvironment('API_BASE_URL', + defaultValue: 'http://localhost:5000'); + // Responsive const kBreakpointMobile = 850.0; diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..e5ca969 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,21 @@ +server { + listen 80; + root /usr/share/nginx/html; + index index.html; + + # Routage par chemin : /set-password?token=... doit servir index.html, + # sinon nginx renvoie 404 sur toute URL profonde. + location / { + try_files $uri $uri/ /index.html; + } + + location ~* \.(js|css|png|jpg|jpeg|gif|svg|woff2?|ttf|json)$ { + expires 7d; + add_header Cache-Control "public"; + } + + # index.html jamais mis en cache, sinon un redéploiement ne se voit pas. + location = /index.html { + add_header Cache-Control "no-store, must-revalidate"; + } +}