From bf570ca3b14ecb69ef248363f51365671a280e47 Mon Sep 17 00:00:00 2001 From: Justin Geibel Date: Fri, 15 Nov 2019 13:05:22 -0500 Subject: [PATCH 1/4] Add a `USE_FASTBOOT=staging-experimental` mode --- config/nginx.conf.erb | 38 ++++++++++++++++++++++++++++---------- script/start-web.sh | 10 +++++----- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/config/nginx.conf.erb b/config/nginx.conf.erb index 1067911f9f4..3435fc6dc4a 100644 --- a/config/nginx.conf.erb +++ b/config/nginx.conf.erb @@ -107,7 +107,7 @@ http { upstream app_server { server localhost:8888 fail_timeout=0; - } + } server { listen <%= ENV["PORT"] %>; @@ -130,15 +130,33 @@ http { rewrite ^ https://$host$request_uri? permanent; } - location / { - proxy_pass http://app_server; - } - - <% if ENV['USE_FASTBOOT'] %> - # Just in case, only forward "/policies" to Ember for a moment - location = /policies { - proxy_pass http://localhost:9000; - } + <% if ENV['USE_FASTBOOT'] == "staging-experimental" %> + # Experimentally send all non-backend requests to FastBoot + + location /api/ { + proxy_pass http://app_server; + } + + # FastBoot + location / { + proxy_pass http://localhost:9000; + } + <% elsif ['USE_FASTBOOT'] %> + # Fastboot is enabled only for allowed paths + + location = /policies { + proxy_pass http://localhost:9000; + } + + location / { + proxy_pass http://app_server; + } + <% else %> + # FastBoot is disabled, backend sends the static Ember index HTML for non-backend paths + + location / { + proxy_pass http://app_server; + } <% end %> location ~ ^/api/v./crates/new$ { diff --git a/script/start-web.sh b/script/start-web.sh index 47317d0867c..dce52263cd1 100755 --- a/script/start-web.sh +++ b/script/start-web.sh @@ -1,12 +1,12 @@ #! /bin/bash set -ue -if [[ "${USE_FASTBOOT:-0}" = 1 ]]; then - export USE_FASTBOOT=1 +if [[ -z "${USE_FASTBOOT}" ]]; then + unset USE_FASTBOOT + bin/start-nginx ./target/release/server +else + export USE_FASTBOOT node --optimize_for_size --max_old_space_size=200 fastboot.js & bin/start-nginx ./target/release/server & wait -n -else - unset USE_FASTBOOT - bin/start-nginx ./target/release/server fi From a423d44a647ce7dbf105b97d276a122ddc9344ad Mon Sep 17 00:00:00 2001 From: Justin Geibel Date: Mon, 2 Dec 2019 22:00:37 -0500 Subject: [PATCH 2/4] Update `ember.sh` fastboot test to match production This script is reference from `package.json` and devlopment should behave the same as production. --- script/ember.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/ember.sh b/script/ember.sh index b67e00cabdb..50c7c68e75a 100755 --- a/script/ember.sh +++ b/script/ember.sh @@ -3,7 +3,7 @@ set -ue export FASTBOOT_DISABLED -if [ "${USE_FASTBOOT:-0}" = '1' ]; then +if [ -z "${USE_FASTBOOT}" ]; then unset FASTBOOT_DISABLED else FASTBOOT_DISABLED=1 From 32a2295275936c497804021f4dddb9f7a0abb316 Mon Sep 17 00:00:00 2001 From: Justin Geibel Date: Mon, 2 Dec 2019 22:23:03 -0500 Subject: [PATCH 3/4] Fix `USE_FASTBOOT: unbound variable` error when variable is not set Explicitly default to an empty value, to work with `set -u`. --- script/ember.sh | 2 +- script/start-web.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/script/ember.sh b/script/ember.sh index 50c7c68e75a..4029d3ef524 100755 --- a/script/ember.sh +++ b/script/ember.sh @@ -3,7 +3,7 @@ set -ue export FASTBOOT_DISABLED -if [ -z "${USE_FASTBOOT}" ]; then +if [ -z "${USE_FASTBOOT-}" ]; then unset FASTBOOT_DISABLED else FASTBOOT_DISABLED=1 diff --git a/script/start-web.sh b/script/start-web.sh index dce52263cd1..bcf62b29efc 100755 --- a/script/start-web.sh +++ b/script/start-web.sh @@ -1,7 +1,7 @@ #! /bin/bash set -ue -if [[ -z "${USE_FASTBOOT}" ]]; then +if [[ -z "${USE_FASTBOOT-}" ]]; then unset USE_FASTBOOT bin/start-nginx ./target/release/server else From 8e02c1e81295f3a7badb65dcc47abcfbab053d11 Mon Sep 17 00:00:00 2001 From: Justin Geibel Date: Thu, 5 Dec 2019 20:08:48 -0500 Subject: [PATCH 4/4] Fix logic inversion in `script/ember.sh` --- script/ember.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/script/ember.sh b/script/ember.sh index 4029d3ef524..6a8a1a56f61 100755 --- a/script/ember.sh +++ b/script/ember.sh @@ -4,9 +4,9 @@ set -ue export FASTBOOT_DISABLED if [ -z "${USE_FASTBOOT-}" ]; then - unset FASTBOOT_DISABLED -else FASTBOOT_DISABLED=1 +else + unset FASTBOOT_DISABLED fi ember "$@"