You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently the SmartApp and other nginx apps like WaalKade are proxied on path prefixes like https://pdok.smartemission.nl/smartapp. As to still allow local resources (javascript, css, media) to be served, the prefix-path /smartapp is rewritten in Kubernetes Ingress to /smartapp/ (trailing slash). This does not work nicely in all deployment contexts, in particular Traefik. Also it is a different method as used with (Flask) Python Apps. There the HTTP Header X_SCRIPT_NAME is set in the related Ingress and handled internally within the Flask app.
It appears to be possible to use the same X_SCRIPT_NAME mechanism to work for nginx backend apps. Thus the rewrite is not required anymore.
This can be effected by a simple addition to the nginx config, using the sub_filter feature on HTML (by default) and JavaScript (sub_filter_types application/javascript) content:
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
location / {
# rewrite ^([^.]*[^/])$ $uri/ permanent;
root /usr/share/nginx/html/smartapp;
# substitute /SCRIPT_NAME so if proxied the proper URLs are set
sub_filter_once off;
sub_filter_types application/javascript;
sub_filter "/X_SCRIPT_NAME" $http_x_script_name;
index index.html;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
The HTML and JavaScript content will need to have /X_SCRIPT_NAME in the content e.g.
This replaces href="/X_SCRIPT_NAME/... with e.g. href="/smartapp/... when the X_SCRIPT_NAME header is set. If not set, e.g. when accessed directly this substitutes to href="/... and resolves as well. A very basic form of templating.
The nice thing is that we have a single method within the Ingress-es (proxy_set_header X-Script-Name) and getting rid of the sometimes problematic rewrite.
The above solution was applied, but is in the long term too complex and cumbersome. The latest version (see also README) has the following characteristics, which make proxying much easier:
the nginx app does the redirect itself
the nginx app requires the /app path i.s.o. root, e.g. /smartapp
the nginx app is unaware of this, assumes root path
all the above is solved in the nginx config
Example for SmartApp config:
server {
listen 80 default_server;
absolute_redirect off;
location /smartapp {
root /usr/share/nginx/html;
index index.html;
}
.
.
}
app is installed under /usr/share/nginx/html/smartapp so resolves
/smartapp is always redirected 301 to /smartapp/
absolute_redirect off keeps outer host/port even when redirecting
For Traefik in Docker the Compose config is now simply:
Currently the SmartApp and other nginx apps like WaalKade are proxied on path prefixes like https://pdok.smartemission.nl/smartapp. As to still allow local resources (javascript, css, media) to be served, the prefix-path
/smartapp
is rewritten in Kubernetes Ingress to/smartapp/
(trailing slash). This does not work nicely in all deployment contexts, in particular Traefik. Also it is a different method as used with (Flask) Python Apps. There the HTTP HeaderX_SCRIPT_NAME
is set in the related Ingress and handled internally within the Flask app.It appears to be possible to use the same
X_SCRIPT_NAME
mechanism to work fornginx
backend apps. Thus the rewrite is not required anymore.This can be effected by a simple addition to the
nginx
config, using thesub_filter
feature on HTML (by default) and JavaScript (sub_filter_types application/javascript
) content:The HTML and JavaScript content will need to have
/X_SCRIPT_NAME
in the content e.g.This replaces
href="/X_SCRIPT_NAME/...
with e.g.href="/smartapp/...
when theX_SCRIPT_NAME
header is set. If not set, e.g. when accessed directly this substitutes tohref="/...
and resolves as well. A very basic form of templating.The SmartApp Ingress needs to be adapted to:
The nice thing is that we have a single method within the Ingress-es (
proxy_set_header X-Script-Name
) and getting rid of the sometimes problematic rewrite.In
docker-compose
this becomesThe text was updated successfully, but these errors were encountered: