From 1e6514895a953a27a86499d8375524d3ce4c366c Mon Sep 17 00:00:00 2001
From: Matthieu Benoist <mbenoist@ausy-group.com>
Date: Fri, 12 Mar 2021 16:08:11 +0100
Subject: [PATCH] ngninx configuration changes

---
 docker-compose-development.rendertron.yml | 18 ++++++++--
 docker/dev/nginx-development-proxy.conf   | 40 +++++------------------
 package.json                              |  4 +--
 readme.md                                 | 11 +++++++
 4 files changed, 36 insertions(+), 37 deletions(-)

diff --git a/docker-compose-development.rendertron.yml b/docker-compose-development.rendertron.yml
index fed87f50..02ada2ac 100644
--- a/docker-compose-development.rendertron.yml
+++ b/docker-compose-development.rendertron.yml
@@ -5,6 +5,14 @@ services:
     build:
       context: ./docker/dev/
       dockerfile: Dockerfile-rendertron
+    networks:
+      - default
+      - grandlyon
+    labels:
+      - "traefik.frontend.rule=Host:rendertron.data.grandlyon.docker"
+      - "traefik.port=8083"
+      - "traefik.protocol=http"
+      - "traefik.docker.network=grandlyon"
 
   proxy:
     build:
@@ -13,12 +21,16 @@ services:
     volumes:
       - ./docker/dev/nginx-development-proxy.conf:/etc/nginx/conf.d/default.conf
     labels:
-      - "traefik.fronted.rule=Host:data.grandlyon.docker"
+      - "traefik.frontend.rule=Host:data.grandlyon.docker"
       - "traefik.port=80"
+      - "traefik.protocol=http"
       - "traefik.docker.network=grandlyon"
     networks:
-      - default
-      - grandlyon
+      default:
+        aliases:
+          - data.grandlyon.docker
+      grandlyon:
+
 
 networks:
   grandlyon:
diff --git a/docker/dev/nginx-development-proxy.conf b/docker/dev/nginx-development-proxy.conf
index eb8700ce..671013bc 100644
--- a/docker/dev/nginx-development-proxy.conf
+++ b/docker/dev/nginx-development-proxy.conf
@@ -1,33 +1,11 @@
 server {
     # staging server is listening on the port 8180
     listen 80;
-    server_name data.grandlyon.docker;
+    server_name data.grandlyon.docker proxy;
     root /usr/share/nginx/html/;
 
-    set $en 0;
 
-    # rule serving the fr build
     location / {
-
-      try_files $uri $uri/ @prerender;
-
-      #  try_files $uri$args /index.html; => used in the prerender =0 block
-
-    }
-
-    # Rule serving the en build
-    location /en {
-        #try_files $uri$args /en/index.html;
-        set $en 1;
-    }
-
-    # redirecting the /fr url to the new location of the fr build
-    location ~ ^/fr(.*)$ {
-        return 301 $scheme://$http_host$1$is_args$args;
-    }
-
-    location @prerender {
-      #proxy_set_header X-Prerender-Token YOUR_TOKEN;
       set $prerender 0;
       if ($http_user_agent ~* "googlebot|yahoo|bingbot|baiduspider|yandex|yeti|yodaobot|gigabot|ia_archiver|facebookexternalhit|twitterbot|linkedinbot|developers\.google\.com") {
           set $prerender 1;
@@ -38,23 +16,21 @@ server {
       if ($http_user_agent ~ "Prerender") {
           set $prerender 0;
       }
+      # Dev only - allow to test request image when forcing the user agent.
+      if ($request_uri ~* "gif|png|jpg|pdf|svg|jpeg") {
+        set $prerender 0;
+      }
 
       if ($prerender = 1) {
-        rewrite .* /render/$scheme://$server_name$request_uri break;
+        rewrite .* /render/http://$server_name$request_uri break;
         proxy_pass http://rendertron:8083;
+        add_header Access-Control-Allow-Origin *;
       }
 
-      if ($en = 0) {
-        rewrite .* /index.html break;
-        #sub_filter '<html lang="en">' '<html lang="fr">';
+      if ($prerender = 0) {
         proxy_pass http://host.docker.internal:4200;
         add_header Access-Control-Allow-Origin *;
       }
-      if ($en = 1) {
-        rewrite .*/en/index.html break;
-        proxy_pass http://host.docker.internal:4200;
-      }
-
     }
 
     #location /robots.txt {
diff --git a/package.json b/package.json
index 0c8a36de..c0faa92a 100644
--- a/package.json
+++ b/package.json
@@ -5,8 +5,8 @@
   "scripts": {
     "ng": "ng",
     "start": "ng serve --proxy-config proxy.conf.json",
-    "start-aot-fr": "ng serve --configuration=aot-fr",
-    "start-aot-en": "ng serve --configuration=aot-en",
+    "start-aot-fr": "ng serve --configuration=aot-fr --disable-host-check",
+    "start-aot-en": "ng serve --configuration=aot-en --disable-host-check",
     "build-i18n:dev": "for lang in en fr; do node --max_old_space_size=4096 ./node_modules/@angular/cli/bin/ng build --configuration=development-$lang --delete-output-path false; done",
     "build-i18n:prod": "for lang in en fr; do node --max_old_space_size=4096 ./node_modules/@angular/cli/bin/ng build --configuration=production-$lang --delete-output-path false; done",
     "win-build-i18n:fr": "node --max_old_space_size=2048 ./node_modules/@angular/cli/bin/ng build --configuration=development-fr --delete-output-path false",
diff --git a/readme.md b/readme.md
index 6962d01f..e0aaec17 100644
--- a/readme.md
+++ b/readme.md
@@ -27,6 +27,17 @@ Using the npm script (which use the Angular CLI):
 npm run start
 ```
 
+### Using with rendertron
+
+Add 127.0.0.1 data.grandlyon.docker rendertron.data.grandlyon.docker to your host
+Run the container with 
+
+```bash
+docker-compose -f docker-compose-developement.rendertron.yml up -d 
+```
+
+Start the web application with npm. You can no acces to both app and SSR version through the 2 domains aforesaid.
+
 ### Build the application
 
 We defined in the package.json two scripts that can build the application. One that generates an optimized build and the other an unoptimized build. The optimized build takes longer than the normal one.
-- 
GitLab