Skip to content

Commit

Permalink
Add mailhog proxy for single lb support (#247)
Browse files Browse the repository at this point in the history
  • Loading branch information
piyushroshan authored May 8, 2024
1 parent 8ac6134 commit 1c5162a
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 1 deletion.
1 change: 1 addition & 0 deletions deploy/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ services:
- COMMUNITY_SERVICE=crapi-community:${COMMUNITY_SERVER_PORT:-8087}
- IDENTITY_SERVICE=crapi-identity:${IDENTITY_SERVER_PORT:-8080}
- WORKSHOP_SERVICE=crapi-workshop:${WORKSHOP_SERVER_PORT:-8000}
- MAILHOG_WEB_SERVICE=mailhog:8025
- TLS_ENABLED=${TLS_ENABLED:-false}
depends_on:
crapi-community:
Expand Down
1 change: 1 addition & 0 deletions deploy/helm/templates/web/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ data:
COMMUNITY_SERVICE: {{ .Values.community.service.name }}:{{ .Values.community.port }}
IDENTITY_SERVICE: {{ .Values.identity.service.name }}:{{ .Values.identity.port }}
WORKSHOP_SERVICE: {{ .Values.workshop.service.name }}:{{ .Values.workshop.port }}
MAILHOG_WEB_SERVICE: {{ .Values.mailhog.service.name }}:{{ .Values.mailhog.webPort }}
TLS_ENABLED: {{ .Values.tlsEnabled | quote }}
2 changes: 1 addition & 1 deletion services/web/nginx-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ else
fi
ls -al /app/certs
env
envsubst '${HTTP_PROTOCOL} ${COMMUNITY_SERVICE} ${IDENTITY_SERVICE} ${WORKSHOP_SERVICE}' < $NGINX_TEMPLATE > /etc/nginx/conf.d/default.conf
envsubst '${HTTP_PROTOCOL} ${COMMUNITY_SERVICE} ${IDENTITY_SERVICE} ${WORKSHOP_SERVICE} ${MAILHOG_WEB_SERVICE}' < $NGINX_TEMPLATE > /etc/nginx/conf.d/default.conf
openresty
exec "$@"
34 changes: 34 additions & 0 deletions services/web/nginx.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,23 @@ server {
proxy_pass ${HTTP_PROTOCOL}://${IDENTITY_SERVICE}/identity/api/auth/jwks.json;
}

location /mailhog/ {
rewrite_by_lua_block {
ngx.req.read_body() -- explicitly read the req body
local body = ngx.req.get_body_data()
if body then
body = ngx.re.gsub(body, ngx.var.scheme.."://"..ngx.var.http_host, "http://${MAILHOG_WEB_SERVICE}")
ngx.req.set_body_data(body)
end
}
proxy_pass http://${MAILHOG_WEB_SERVICE}/;
proxy_set_header Host ${MAILHOG_WEB_SERVICE};
proxy_set_header X-Forwarded-Host $http_host;
sub_filter_types application/json text/html;
sub_filter "http://${MAILHOG_WEB_SERVICE}" "$scheme://$http_host";
sub_filter_once off;
}

location / {
try_files $uri /index.html =404;
add_header Last-Modified $date_gmt;
Expand Down Expand Up @@ -139,6 +156,23 @@ server {
proxy_pass ${HTTP_PROTOCOL}://${IDENTITY_SERVICE}/identity/api/auth/jwks.json;
}

location /mailhog/ {
rewrite_by_lua_block {
ngx.req.read_body() -- explicitly read the req body
local body = ngx.req.get_body_data()
if body then
body = ngx.re.gsub(body, ngx.var.scheme.."://"..ngx.var.http_host, "http://${MAILHOG_WEB_SERVICE}")
ngx.req.set_body_data(body)
end
}
proxy_pass http://${MAILHOG_WEB_SERVICE}/;
proxy_set_header Host ${MAILHOG_WEB_SERVICE};
proxy_set_header X-Forwarded-Host $http_host;
sub_filter_types application/json text/html;
sub_filter "http://${MAILHOG_WEB_SERVICE}" "$scheme://$http_host";
sub_filter_once off;
}

location / {
try_files $uri /index.html =404;
add_header Last-Modified $date_gmt;
Expand Down
36 changes: 36 additions & 0 deletions services/web/nginx.ssl.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,25 @@ server {
proxy_ssl_trusted_certificate /app/certs/server.crt;
}

location /mailhog/ {
rewrite_by_lua_block {
ngx.req.read_body() -- explicitly read the req body
local body = ngx.req.get_body_data()
if body then
body = ngx.re.gsub(body, ngx.var.scheme.."://"..ngx.var.http_host, "http://${MAILHOG_WEB_SERVICE}")
ngx.req.set_body_data(body)
end
}
proxy_pass http://${MAILHOG_WEB_SERVICE}/;
proxy_set_header Host ${MAILHOG_WEB_SERVICE};
proxy_set_header X-Forwarded-Host $http_host;
sub_filter_types application/json text/html;
sub_filter "http://${MAILHOG_WEB_SERVICE}" "$scheme://$http_host";
sub_filter_once off;
proxy_ssl_verify off;
proxy_ssl_trusted_certificate /app/certs/server.crt;
}

location / {
try_files $uri /index.html =404;
add_header Last-Modified $date_gmt;
Expand Down Expand Up @@ -146,6 +165,23 @@ server {
proxy_pass ${HTTP_PROTOCOL}://${IDENTITY_SERVICE}/identity/api/auth/jwks.json;
}

location /mailhog/ {
rewrite_by_lua_block {
ngx.req.read_body() -- explicitly read the req body
local body = ngx.req.get_body_data()
if body then
body = ngx.re.gsub(body, ngx.var.scheme.."://"..ngx.var.http_host, "http://${MAILHOG_WEB_SERVICE}")
ngx.req.set_body_data(body)
end
}
proxy_pass http://${MAILHOG_WEB_SERVICE}/;
proxy_set_header Host ${MAILHOG_WEB_SERVICE};
proxy_set_header X-Forwarded-Host $http_host;
sub_filter_types application/json text/html;
sub_filter "http://${MAILHOG_WEB_SERVICE}" "$scheme://$http_host";
sub_filter_once off;
}

location / {
try_files $uri /index.html =404;
add_header Last-Modified $date_gmt;
Expand Down

0 comments on commit 1c5162a

Please sign in to comment.