diff --git a/client/Dockerfile b/client/Dockerfile index b71165fa..708b48af 100644 --- a/client/Dockerfile +++ b/client/Dockerfile @@ -18,6 +18,7 @@ COPY docker-start.sh / WORKDIR /etc/nginx COPY nginx.conf.docker ./nginx.conf +COPY metatags.lua . WORKDIR /var/www COPY --from=builder /opt/app/public/ . @@ -26,7 +27,8 @@ COPY --from=builder /opt/app/public/ . FROM openresty/openresty:alpine-fat as release RUN apk --no-cache add dumb-init -RUN /usr/local/openresty/luajit/bin/luarocks install gumbo +RUN opm get bungle/lua-resty-template +# RUN /usr/local/openresty/luajit/bin/luarocks install gumbo COPY --from=approot / / CMD ["/docker-start.sh"] diff --git a/client/html/index.htm b/client/html/index.htm index 00728903..951e6b8a 100644 --- a/client/html/index.htm +++ b/client/html/index.htm @@ -22,6 +22,7 @@ + {{ generated_head_tags }}
diff --git a/client/metatags.lua b/client/metatags.lua new file mode 100644 index 00000000..586a1fc4 --- /dev/null +++ b/client/metatags.lua @@ -0,0 +1,32 @@ +ngx.req.read_body() + +local page_html = ngx.location.capture("/index.htm") + +ngx.req.set_header("Accept", "application/json") +local server_info = cjson.decode((ngx.location.capture("/_internal_api/info")).body) + +-- local document = gumbo.parse(page_html.body) +-- +-- function add_meta_tag (property, content) +-- local new_element = document:createElement("meta") +-- document.head:appendChild(new_element) +-- new_element:setAttribute("property", property) +-- new_element:setAttribute("content", content) +-- end + +local additional_tags = "" + +local function add_meta_tag (property, content) + additional_tags = additional_tags .. "" +end + +-- Add the site name tag +add_meta_tag("og:site_name", server_info.config.name) + +local final_response = page_html.body:gsub("{{ generated_head_tags }}", additional_tags) + +-- Set the content type back to HTML +ngx.header.content_type = 'text/html'; + +-- ngx.say(page_html.body) +ngx.say(final_response) diff --git a/client/nginx.conf.docker b/client/nginx.conf.docker index 58545e84..3040dfaf 100644 --- a/client/nginx.conf.docker +++ b/client/nginx.conf.docker @@ -27,7 +27,7 @@ http { init_by_lua_block { cjson = require("cjson") - gumbo = require("gumbo") + -- gumbo = require("gumbo") } server { @@ -81,7 +81,7 @@ http { location / { root /var/www; - try_files $uri /index.htm; + try_files $uri /_og_tags_html; sendfile on; tcp_nopush on; @@ -104,23 +104,9 @@ http { 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) - } + content_by_lua_file /etc/nginx/metatags.lua; } location @unauthorized {