client: using openresty for content rewriting

This commit is contained in:
Ben Klein 2021-07-10 02:34:23 +00:00
parent f96274033b
commit b2800ad779
3 changed files with 45 additions and 4 deletions

View file

@ -23,9 +23,10 @@ WORKDIR /var/www
COPY --from=builder /opt/app/public/ .
FROM nginx:alpine as release
FROM openresty/openresty:alpine-fat as release
RUN apk --no-cache add dumb-init
RUN /usr/local/openresty/luajit/bin/luarocks install gumbo
COPY --from=approot / /
CMD ["/docker-start.sh"]

View file

@ -8,4 +8,5 @@ sed -i "s|__BASEURL__|${BASE_URL:-/}|g" \
/var/www/manifest.json
# Start server
exec nginx
echo "$0 starting server..."
exec openresty -c /etc/nginx/nginx.conf

View file

@ -1,5 +1,7 @@
worker_processes 1;
user nginx;
user nobody;
pcre_jit on;
error_log /dev/stderr warn;
pid /var/run/nginx.pid;
@ -9,7 +11,7 @@ events {
}
http {
include /etc/nginx/mime.types;
include /usr/local/openresty/nginx/conf/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr -> $request [$status] - '
@ -23,6 +25,11 @@ http {
server __BACKEND__:6666;
}
init_by_lua_block {
cjson = require("cjson")
gumbo = require("gumbo")
}
server {
listen 80 default_server;
@ -84,6 +91,38 @@ http {
gzip_proxied expired no-cache no-store private auth;
}
location ~ ^/_internal_api/(.*)$ {
internal;
tcp_nodelay on;
add_header 'Access-Control-Allow-Origin' '*';
gzip off;
proxy_connect_timeout 10s;
proxy_send_timeout 10s;
proxy_read_timeout 10s;
proxy_pass http://backend/$1;
}
location ~ ^/_internal_tag_generator/(.*)$ {
content_by_lua_block {
ngx.say("")
}
}
location /_og_tags_html {
root /var/www;
content_by_lua_block {
ngx.req.read_body()
local page_html = ngx.location.capture("/index.htm")
ngx.say(page_html.body)
ngx.req.set_header("Accept", "application/json")
local server_info = cjson.decode((ngx.location.capture("/_internal_api/info")).body)
ngx.say(server_info.config.name)
}
}
location @unauthorized {
return 403 "Unauthorized";
default_type text/plain;