Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

nginx: Serve JSON for 502/503/504 errors on API routes.

Sarvesh-ml8ae7545ad33e
diff --git a/puppet/zulip/files/nginx/zulip-include-frontend/api_5xx.json b/puppet/zulip/files/nginx/zulip-include-frontend/api_5xx.json
new file mode 100644
index 00000000000..5cfc25ec715
--- /dev/null
+++ b/puppet/zulip/files/nginx/zulip-include-frontend/api_5xx.json
@@ -0,0 +1,4 @@
+{
+ "result": "error",
+ "msg": "Server temporarily unavailable"
+}
diff --git a/puppet/zulip/files/nginx/zulip-include-frontend/app b/puppet/zulip/files/nginx/zulip-include-frontend/app
index 517cd4206fa..7bf3dd716fd 100644
--- a/puppet/zulip/files/nginx/zulip-include-frontend/app
+++ b/puppet/zulip/files/nginx/zulip-include-frontend/app
@@ -60,6 +60,7 @@ location /help {
# Send longpoll requests to Tornado
location = /json/events {
+ error_page 502 503 504 /api_5xx.json;
if ($request_method = 'OPTIONS') {
# add_header does not propagate into/out of blocks, so this
# include cannot be factored out
@@ -82,6 +83,7 @@ location = /json/events {
# Send longpoll requests to Tornado
location = /api/v1/events {
+ error_page 502 503 504 /api_5xx.json;
if ($request_method = 'OPTIONS') {
include /etc/nginx/zulip-include/tornado_cors_headers;
@@ -108,6 +110,7 @@ location ~ ^/internal/tornado/(\d+)(/.*)$ {
}
location /api/v1/tus {
+ error_page 502 503 504 /api_5xx.json;
include /etc/nginx/zulip-include/api_headers;
include /etc/nginx/zulip-include/proxy;
# https://github.com/tus/tusd/blob/main/examples/nginx.conf
@@ -124,6 +127,19 @@ location / {
include uwsgi_params;
}
+# JSON routes used by the web app
+location /json/ {
+ error_page 502 503 504 /api_5xx.json;
+ include uwsgi_params;
+}
+
+location = /api_5xx.json {
+ internal;
+ include /etc/nginx/zulip-include/api_headers;
+ default_type application/json;
+ alias /etc/nginx/zulip-include/api_5xx.json;
+}
+
# These Django routes not under /api are shared between mobile and
# web, and thus need API headers added. We can't easily collapse
# these blocks with the /api block, because regular expressions take
@@ -157,6 +173,7 @@ location /api/internal/ {
# Send all API routes not covered above to Django via uWSGI
location /api/ {
+ error_page 502 503 504 /api_5xx.json;
include /etc/nginx/zulip-include/api_headers;
include uwsgi_params;
diff --git a/puppet/zulip/manifests/app_frontend_base.pp b/puppet/zulip/manifests/app_frontend_base.pp
index a9a86441f9f..84bd76cd9ff 100644
--- a/puppet/zulip/manifests/app_frontend_base.pp
+++ b/puppet/zulip/manifests/app_frontend_base.pp
@@ -47,6 +47,14 @@ class zulip::app_frontend_base {
source => 'puppet:///modules/zulip/nginx/zulip-include-frontend/uploads.types',
notify => Service['nginx'],
}
+ file { '/etc/nginx/zulip-include/api_5xx.json':
+ require => Package[$zulip::common::nginx],
+ owner => 'root',
+ group => 'root',
+ mode => '0644',
+ source => 'puppet:///modules/zulip/nginx/zulip-include-frontend/api_5xx.json',
+ notify => Service['nginx'],
+ }
file { '/etc/nginx/zulip-include/app.d/':
ensure => directory,
owner => 'root',