Skip to content

Commit 48a64ae

Browse files
committed
Auto merge of #1907 - jtgeibel:fastboot-staging-experimental, r=carols10cents
Add a `USE_FASTBOOT=staging-experimental` mode This adds a new mode to the `USE_FASTBOOT` environment variable. The logic is now: * When deployed on Heroku (staging or production - via `script/start-web.sh`): * If `USE_FASTBOOT=staging-experimental` then non-backend requests are sent to FastBoot. * If `USE_FASTBOOT` is set and non-zero length, FastBoot is enabled only for allowed paths. * Otherwise (`USE_FASTBOOT` is not set, or is zero length), FastBoot is disabled. * When doing local development (via `script/ember.sh`): * If `USE_FASTBOOT` is set, all (initial) frontend requests are served via FastBoot. This is equivalent to `staging-experimental` above. * If `USE_FASTBOOT` is not set, FastBoot is disabled. Because our development environment doesn't go through nginx, it isn't possible to support the "FastBoot is enabled only for allowed paths" mode. However, once the frontend has booted, all further requests hit the backend (unless JS is disabled, then every client navigation results in a new request served via FastBoot).
2 parents e2e7f65 + 8e02c1e commit 48a64ae

File tree

3 files changed

+36
-18
lines changed

3 files changed

+36
-18
lines changed

config/nginx.conf.erb

+28-10
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ http {
107107

108108
upstream app_server {
109109
server localhost:8888 fail_timeout=0;
110-
}
110+
}
111111

112112
server {
113113
listen <%= ENV["PORT"] %>;
@@ -130,15 +130,33 @@ http {
130130
rewrite ^ https://$host$request_uri? permanent;
131131
}
132132

133-
location / {
134-
proxy_pass http://app_server;
135-
}
136-
137-
<% if ENV['USE_FASTBOOT'] %>
138-
# Just in case, only forward "/policies" to Ember for a moment
139-
location = /policies {
140-
proxy_pass http://localhost:9000;
141-
}
133+
<% if ENV['USE_FASTBOOT'] == "staging-experimental" %>
134+
# Experimentally send all non-backend requests to FastBoot
135+
136+
location /api/ {
137+
proxy_pass http://app_server;
138+
}
139+
140+
# FastBoot
141+
location / {
142+
proxy_pass http://localhost:9000;
143+
}
144+
<% elsif ['USE_FASTBOOT'] %>
145+
# Fastboot is enabled only for allowed paths
146+
147+
location = /policies {
148+
proxy_pass http://localhost:9000;
149+
}
150+
151+
location / {
152+
proxy_pass http://app_server;
153+
}
154+
<% else %>
155+
# FastBoot is disabled, backend sends the static Ember index HTML for non-backend paths
156+
157+
location / {
158+
proxy_pass http://app_server;
159+
}
142160
<% end %>
143161

144162
location ~ ^/api/v./crates/new$ {

script/ember.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ set -ue
33

44
export FASTBOOT_DISABLED
55

6-
if [ "${USE_FASTBOOT:-0}" = '1' ]; then
7-
unset FASTBOOT_DISABLED
8-
else
6+
if [ -z "${USE_FASTBOOT-}" ]; then
97
FASTBOOT_DISABLED=1
8+
else
9+
unset FASTBOOT_DISABLED
1010
fi
1111

1212
ember "$@"

script/start-web.sh

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#! /bin/bash
22
set -ue
33

4-
if [[ "${USE_FASTBOOT:-0}" = 1 ]]; then
5-
export USE_FASTBOOT=1
4+
if [[ -z "${USE_FASTBOOT-}" ]]; then
5+
unset USE_FASTBOOT
6+
bin/start-nginx ./target/release/server
7+
else
8+
export USE_FASTBOOT
69
node --optimize_for_size --max_old_space_size=200 fastboot.js &
710
bin/start-nginx ./target/release/server &
811
wait -n
9-
else
10-
unset USE_FASTBOOT
11-
bin/start-nginx ./target/release/server
1212
fi

0 commit comments

Comments
 (0)