Skip to content

Commit a6fb68e

Browse files
committed
Fix missing 404/500 error pages for errors served by Puma.
If the Puma web-app served default 404/500 errors, the response body was blank, since the error pages had gotten removed in fc684f5 This brings the error pages back and integrates them into the build process for keeping the "public" directory out-of-source (for making the asset building easier).
1 parent 4d5cc3f commit a6fb68e

File tree

9 files changed

+50
-7
lines changed

9 files changed

+50
-7
lines changed

build/cmake/core-web-app.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ add_custom_command(
1313
COMMAND touch ${STAMP_DIR}/core-web-app-bundle
1414
)
1515

16+
file(GLOB_RECURSE web_app_public_files
17+
${CMAKE_SOURCE_DIR}/src/api-umbrella/web-app/public/*.html
18+
)
19+
add_custom_command(
20+
OUTPUT ${STAMP_DIR}/core-web-app-public
21+
DEPENDS ${web_app_public_files}
22+
COMMAND mkdir -p ${CORE_BUILD_DIR}/tmp/web-app-build/public
23+
COMMAND rsync -a --delete-after ${CMAKE_SOURCE_DIR}/src/api-umbrella/web-app/public/ ${CORE_BUILD_DIR}/tmp/web-app-build/public/
24+
COMMAND touch ${STAMP_DIR}/core-web-app-public
25+
)
26+
1627
file(GLOB_RECURSE web_asset_files
1728
${CMAKE_SOURCE_DIR}/src/api-umbrella/web-app/app/assets/*.css
1829
${CMAKE_SOURCE_DIR}/src/api-umbrella/web-app/app/assets/*.scss

build/cmake/core.cmake

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,16 @@ add_custom_command(
3333
add_custom_command(
3434
OUTPUT
3535
${STAMP_DIR}/core-build-install-dist
36-
${CORE_BUILD_DIR}/releases/0/build/dist/web-app-assets
36+
${CORE_BUILD_DIR}/releases/0/build/dist/web-app-public
3737
${CORE_BUILD_DIR}/releases/0/build/dist/admin-ui
3838
DEPENDS
3939
${STAMP_DIR}/core-admin-ui-build
40+
${STAMP_DIR}/core-web-app-public
4041
${STAMP_DIR}/core-web-app-precompile
4142
${STAMP_DIR}/core-build-release-dir
42-
COMMAND mkdir -p ${CORE_BUILD_DIR}/releases/0/build/dist/web-app-assets
43-
COMMAND rsync -a --delete-after ${CORE_BUILD_DIR}/tmp/web-app-build/web-assets/ ${CORE_BUILD_DIR}/releases/0/build/dist/web-app-assets/web-assets/
43+
COMMAND mkdir -p ${CORE_BUILD_DIR}/releases/0/build/dist/web-app-public
44+
COMMAND rsync -a --delete-after ${CORE_BUILD_DIR}/tmp/web-app-build/public/ ${CORE_BUILD_DIR}/releases/0/build/dist/web-app-public/
45+
COMMAND rsync -a --delete-after ${CORE_BUILD_DIR}/tmp/web-app-build/web-assets/ ${CORE_BUILD_DIR}/releases/0/build/dist/web-app-public/web-assets/
4446
COMMAND rsync -a --delete-after ${CORE_BUILD_DIR}/tmp/admin-ui-build/dist/ ${CORE_BUILD_DIR}/releases/0/build/dist/admin-ui/
4547
COMMAND touch ${STAMP_DIR}/core-build-install-dist
4648
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<html>
2+
<head><title>404 Not Found</title></head>
3+
<body bgcolor="white">
4+
<center><h1>404 Not Found</h1></center>
5+
<hr><center>API Umbrella</center>
6+
</body>
7+
</html>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<html>
2+
<head><title>422 Unprocessable Entity</title></head>
3+
<body bgcolor="white">
4+
<center><h1>422 Unprocessable Entity</h1></center>
5+
<hr><center>API Umbrella</center>
6+
</body>
7+
</html>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<html>
2+
<head><title>500 Internal Server Error</title></head>
3+
<body bgcolor="white">
4+
<center><h1>500 Internal Server Error</h1></center>
5+
<hr><center>API Umbrella</center>
6+
</body>
7+
</html>

templates/etc/nginx/router.conf.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ http {
362362
{{^_development_env?}}
363363
location /web-assets/ {
364364
more_set_headers "Cache-Control: public, max-age=31536000, immutable";
365-
alias {{_embedded_root_dir}}/apps/core/current/build/dist/web-app-assets/web-assets/;
365+
alias {{_embedded_root_dir}}/apps/core/current/build/dist/web-app-public/web-assets/;
366366
}
367367
{{/_development_env?}}
368368

templates/etc/perp/web-delayed-job/rc.env.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ RAILS_ENV={{app_env}}
22
DELAYED_JOB=true
33
API_UMBRELLA_RUNTIME_CONFIG={{_api_umbrella_config_runtime_file}}
44
RAILS_TMP_PATH={{tmp_dir}}/web-app
5-
RAILS_PUBLIC_PATH={{_embedded_root_dir}}/apps/core/current/build/dist/web-app-assets
5+
RAILS_PUBLIC_PATH={{_embedded_root_dir}}/apps/core/current/build/dist/web-app-public
66

77
# Set the HOME path for Bundler to a writable directory to prevent warnings in
88
# Bundler 1.14+: # https://github.com/bundler/bundler/issues/5372 Note that we

templates/etc/perp/web-puma/rc.env.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
RAILS_ENV={{app_env}}
22
API_UMBRELLA_RUNTIME_CONFIG={{_api_umbrella_config_runtime_file}}
33
RAILS_TMP_PATH={{tmp_dir}}/web-app
4-
RAILS_PUBLIC_PATH={{_embedded_root_dir}}/apps/core/current/build/dist/web-app-assets
4+
RAILS_PUBLIC_PATH={{_embedded_root_dir}}/apps/core/current/build/dist/web-app-public
55

66
# Set the HOME path for Bundler to a writable directory to prevent warnings in
77
# Bundler 1.14+: # https://github.com/bundler/bundler/issues/5372 Note that we

test/proxy/test_nginx_rewrites.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ def test_precedence
124124
"^/#{unique_test_id}/api-example/rewrite_me$ https://example.com/ permanent",
125125
"^/#{unique_test_id}/website-example/rewrite_me$ https://2.example.com/ permanent",
126126
"^/admin/rewrite_me$ https://3.example.com/ permanent",
127+
"^/admin/login/rewrite_me$ https://4.example.com/ permanent",
127128
],
128129
},
129130
],
@@ -148,13 +149,21 @@ def test_precedence
148149
assert_response_code(404, response)
149150
assert_match("Test 404 Not Found", response.body)
150151

151-
# Rewrites match before the admin tool.
152+
# Rewrites match before the admin tool's static content.
152153
response = Typhoeus.get("https://127.0.0.1:9081/admin/rewrite_me", http_opts)
153154
assert_response_code(301, response)
154155
assert_equal("https://3.example.com/", response.headers["location"])
155156
response = Typhoeus.get("https://127.0.0.1:9081/admin/rewrite_me_just_kidding", http_opts)
156157
assert_response_code(404, response)
157158
assert_match("<center>openresty</center>", response.body)
159+
160+
# Rewrites match before the admin tool's dynamic app.
161+
response = Typhoeus.get("https://127.0.0.1:9081/admin/login/rewrite_me", http_opts)
162+
assert_response_code(301, response)
163+
assert_equal("https://4.example.com/", response.headers["location"])
164+
response = Typhoeus.get("https://127.0.0.1:9081/admin/login/rewrite_me_just_kidding", http_opts)
165+
assert_response_code(404, response)
166+
assert_match("<center>API Umbrella</center>", response.body)
158167
end
159168
end
160169
end

0 commit comments

Comments
 (0)