Skip to content

Commit

Permalink
Fix missing 404/500 error pages for errors served by Puma.
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
GUI committed May 27, 2018
1 parent 4d5cc3f commit a6fb68e
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 7 deletions.
11 changes: 11 additions & 0 deletions build/cmake/core-web-app.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ add_custom_command(
COMMAND touch ${STAMP_DIR}/core-web-app-bundle
)

file(GLOB_RECURSE web_app_public_files
${CMAKE_SOURCE_DIR}/src/api-umbrella/web-app/public/*.html
)
add_custom_command(
OUTPUT ${STAMP_DIR}/core-web-app-public
DEPENDS ${web_app_public_files}
COMMAND mkdir -p ${CORE_BUILD_DIR}/tmp/web-app-build/public
COMMAND rsync -a --delete-after ${CMAKE_SOURCE_DIR}/src/api-umbrella/web-app/public/ ${CORE_BUILD_DIR}/tmp/web-app-build/public/
COMMAND touch ${STAMP_DIR}/core-web-app-public
)

file(GLOB_RECURSE web_asset_files
${CMAKE_SOURCE_DIR}/src/api-umbrella/web-app/app/assets/*.css
${CMAKE_SOURCE_DIR}/src/api-umbrella/web-app/app/assets/*.scss
Expand Down
8 changes: 5 additions & 3 deletions build/cmake/core.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,16 @@ add_custom_command(
add_custom_command(
OUTPUT
${STAMP_DIR}/core-build-install-dist
${CORE_BUILD_DIR}/releases/0/build/dist/web-app-assets
${CORE_BUILD_DIR}/releases/0/build/dist/web-app-public
${CORE_BUILD_DIR}/releases/0/build/dist/admin-ui
DEPENDS
${STAMP_DIR}/core-admin-ui-build
${STAMP_DIR}/core-web-app-public
${STAMP_DIR}/core-web-app-precompile
${STAMP_DIR}/core-build-release-dir
COMMAND mkdir -p ${CORE_BUILD_DIR}/releases/0/build/dist/web-app-assets
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/
COMMAND mkdir -p ${CORE_BUILD_DIR}/releases/0/build/dist/web-app-public
COMMAND rsync -a --delete-after ${CORE_BUILD_DIR}/tmp/web-app-build/public/ ${CORE_BUILD_DIR}/releases/0/build/dist/web-app-public/
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/
COMMAND rsync -a --delete-after ${CORE_BUILD_DIR}/tmp/admin-ui-build/dist/ ${CORE_BUILD_DIR}/releases/0/build/dist/admin-ui/
COMMAND touch ${STAMP_DIR}/core-build-install-dist
)
Expand Down
7 changes: 7 additions & 0 deletions src/api-umbrella/web-app/public/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>API Umbrella</center>
</body>
</html>
7 changes: 7 additions & 0 deletions src/api-umbrella/web-app/public/422.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<html>
<head><title>422 Unprocessable Entity</title></head>
<body bgcolor="white">
<center><h1>422 Unprocessable Entity</h1></center>
<hr><center>API Umbrella</center>
</body>
</html>
7 changes: 7 additions & 0 deletions src/api-umbrella/web-app/public/500.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<html>
<head><title>500 Internal Server Error</title></head>
<body bgcolor="white">
<center><h1>500 Internal Server Error</h1></center>
<hr><center>API Umbrella</center>
</body>
</html>
2 changes: 1 addition & 1 deletion templates/etc/nginx/router.conf.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ http {
{{^_development_env?}}
location /web-assets/ {
more_set_headers "Cache-Control: public, max-age=31536000, immutable";
alias {{_embedded_root_dir}}/apps/core/current/build/dist/web-app-assets/web-assets/;
alias {{_embedded_root_dir}}/apps/core/current/build/dist/web-app-public/web-assets/;
}
{{/_development_env?}}

Expand Down
2 changes: 1 addition & 1 deletion templates/etc/perp/web-delayed-job/rc.env.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ RAILS_ENV={{app_env}}
DELAYED_JOB=true
API_UMBRELLA_RUNTIME_CONFIG={{_api_umbrella_config_runtime_file}}
RAILS_TMP_PATH={{tmp_dir}}/web-app
RAILS_PUBLIC_PATH={{_embedded_root_dir}}/apps/core/current/build/dist/web-app-assets
RAILS_PUBLIC_PATH={{_embedded_root_dir}}/apps/core/current/build/dist/web-app-public

# Set the HOME path for Bundler to a writable directory to prevent warnings in
# Bundler 1.14+: # https://github.com/bundler/bundler/issues/5372 Note that we
Expand Down
2 changes: 1 addition & 1 deletion templates/etc/perp/web-puma/rc.env.mustache
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
RAILS_ENV={{app_env}}
API_UMBRELLA_RUNTIME_CONFIG={{_api_umbrella_config_runtime_file}}
RAILS_TMP_PATH={{tmp_dir}}/web-app
RAILS_PUBLIC_PATH={{_embedded_root_dir}}/apps/core/current/build/dist/web-app-assets
RAILS_PUBLIC_PATH={{_embedded_root_dir}}/apps/core/current/build/dist/web-app-public

# Set the HOME path for Bundler to a writable directory to prevent warnings in
# Bundler 1.14+: # https://github.com/bundler/bundler/issues/5372 Note that we
Expand Down
11 changes: 10 additions & 1 deletion test/proxy/test_nginx_rewrites.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def test_precedence
"^/#{unique_test_id}/api-example/rewrite_me$ https://example.com/ permanent",
"^/#{unique_test_id}/website-example/rewrite_me$ https://2.example.com/ permanent",
"^/admin/rewrite_me$ https://3.example.com/ permanent",
"^/admin/login/rewrite_me$ https://4.example.com/ permanent",
],
},
],
Expand All @@ -148,13 +149,21 @@ def test_precedence
assert_response_code(404, response)
assert_match("Test 404 Not Found", response.body)

# Rewrites match before the admin tool.
# Rewrites match before the admin tool's static content.
response = Typhoeus.get("https://127.0.0.1:9081/admin/rewrite_me", http_opts)
assert_response_code(301, response)
assert_equal("https://3.example.com/", response.headers["location"])
response = Typhoeus.get("https://127.0.0.1:9081/admin/rewrite_me_just_kidding", http_opts)
assert_response_code(404, response)
assert_match("<center>openresty</center>", response.body)

# Rewrites match before the admin tool's dynamic app.
response = Typhoeus.get("https://127.0.0.1:9081/admin/login/rewrite_me", http_opts)
assert_response_code(301, response)
assert_equal("https://4.example.com/", response.headers["location"])
response = Typhoeus.get("https://127.0.0.1:9081/admin/login/rewrite_me_just_kidding", http_opts)
assert_response_code(404, response)
assert_match("<center>API Umbrella</center>", response.body)
end
end
end

0 comments on commit a6fb68e

Please sign in to comment.