Skip to content

Commit 1c5162a

Browse files
authored
Add mailhog proxy for single lb support (#247)
1 parent 8ac6134 commit 1c5162a

File tree

5 files changed

+73
-1
lines changed

5 files changed

+73
-1
lines changed

deploy/docker/docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ services:
155155
- COMMUNITY_SERVICE=crapi-community:${COMMUNITY_SERVER_PORT:-8087}
156156
- IDENTITY_SERVICE=crapi-identity:${IDENTITY_SERVER_PORT:-8080}
157157
- WORKSHOP_SERVICE=crapi-workshop:${WORKSHOP_SERVER_PORT:-8000}
158+
- MAILHOG_WEB_SERVICE=mailhog:8025
158159
- TLS_ENABLED=${TLS_ENABLED:-false}
159160
depends_on:
160161
crapi-community:

deploy/helm/templates/web/configmap.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ data:
99
COMMUNITY_SERVICE: {{ .Values.community.service.name }}:{{ .Values.community.port }}
1010
IDENTITY_SERVICE: {{ .Values.identity.service.name }}:{{ .Values.identity.port }}
1111
WORKSHOP_SERVICE: {{ .Values.workshop.service.name }}:{{ .Values.workshop.port }}
12+
MAILHOG_WEB_SERVICE: {{ .Values.mailhog.service.name }}:{{ .Values.mailhog.webPort }}
1213
TLS_ENABLED: {{ .Values.tlsEnabled | quote }}

services/web/nginx-wrapper.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ else
2323
fi
2424
ls -al /app/certs
2525
env
26-
envsubst '${HTTP_PROTOCOL} ${COMMUNITY_SERVICE} ${IDENTITY_SERVICE} ${WORKSHOP_SERVICE}' < $NGINX_TEMPLATE > /etc/nginx/conf.d/default.conf
26+
envsubst '${HTTP_PROTOCOL} ${COMMUNITY_SERVICE} ${IDENTITY_SERVICE} ${WORKSHOP_SERVICE} ${MAILHOG_WEB_SERVICE}' < $NGINX_TEMPLATE > /etc/nginx/conf.d/default.conf
2727
openresty
2828
exec "$@"

services/web/nginx.conf.template

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,23 @@ server {
6666
proxy_pass ${HTTP_PROTOCOL}://${IDENTITY_SERVICE}/identity/api/auth/jwks.json;
6767
}
6868

69+
location /mailhog/ {
70+
rewrite_by_lua_block {
71+
ngx.req.read_body() -- explicitly read the req body
72+
local body = ngx.req.get_body_data()
73+
if body then
74+
body = ngx.re.gsub(body, ngx.var.scheme.."://"..ngx.var.http_host, "http://${MAILHOG_WEB_SERVICE}")
75+
ngx.req.set_body_data(body)
76+
end
77+
}
78+
proxy_pass http://${MAILHOG_WEB_SERVICE}/;
79+
proxy_set_header Host ${MAILHOG_WEB_SERVICE};
80+
proxy_set_header X-Forwarded-Host $http_host;
81+
sub_filter_types application/json text/html;
82+
sub_filter "http://${MAILHOG_WEB_SERVICE}" "$scheme://$http_host";
83+
sub_filter_once off;
84+
}
85+
6986
location / {
7087
try_files $uri /index.html =404;
7188
add_header Last-Modified $date_gmt;
@@ -139,6 +156,23 @@ server {
139156
proxy_pass ${HTTP_PROTOCOL}://${IDENTITY_SERVICE}/identity/api/auth/jwks.json;
140157
}
141158

159+
location /mailhog/ {
160+
rewrite_by_lua_block {
161+
ngx.req.read_body() -- explicitly read the req body
162+
local body = ngx.req.get_body_data()
163+
if body then
164+
body = ngx.re.gsub(body, ngx.var.scheme.."://"..ngx.var.http_host, "http://${MAILHOG_WEB_SERVICE}")
165+
ngx.req.set_body_data(body)
166+
end
167+
}
168+
proxy_pass http://${MAILHOG_WEB_SERVICE}/;
169+
proxy_set_header Host ${MAILHOG_WEB_SERVICE};
170+
proxy_set_header X-Forwarded-Host $http_host;
171+
sub_filter_types application/json text/html;
172+
sub_filter "http://${MAILHOG_WEB_SERVICE}" "$scheme://$http_host";
173+
sub_filter_once off;
174+
}
175+
142176
location / {
143177
try_files $uri /index.html =404;
144178
add_header Last-Modified $date_gmt;

services/web/nginx.ssl.conf.template

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,25 @@ server {
7373
proxy_ssl_trusted_certificate /app/certs/server.crt;
7474
}
7575

76+
location /mailhog/ {
77+
rewrite_by_lua_block {
78+
ngx.req.read_body() -- explicitly read the req body
79+
local body = ngx.req.get_body_data()
80+
if body then
81+
body = ngx.re.gsub(body, ngx.var.scheme.."://"..ngx.var.http_host, "http://${MAILHOG_WEB_SERVICE}")
82+
ngx.req.set_body_data(body)
83+
end
84+
}
85+
proxy_pass http://${MAILHOG_WEB_SERVICE}/;
86+
proxy_set_header Host ${MAILHOG_WEB_SERVICE};
87+
proxy_set_header X-Forwarded-Host $http_host;
88+
sub_filter_types application/json text/html;
89+
sub_filter "http://${MAILHOG_WEB_SERVICE}" "$scheme://$http_host";
90+
sub_filter_once off;
91+
proxy_ssl_verify off;
92+
proxy_ssl_trusted_certificate /app/certs/server.crt;
93+
}
94+
7695
location / {
7796
try_files $uri /index.html =404;
7897
add_header Last-Modified $date_gmt;
@@ -146,6 +165,23 @@ server {
146165
proxy_pass ${HTTP_PROTOCOL}://${IDENTITY_SERVICE}/identity/api/auth/jwks.json;
147166
}
148167

168+
location /mailhog/ {
169+
rewrite_by_lua_block {
170+
ngx.req.read_body() -- explicitly read the req body
171+
local body = ngx.req.get_body_data()
172+
if body then
173+
body = ngx.re.gsub(body, ngx.var.scheme.."://"..ngx.var.http_host, "http://${MAILHOG_WEB_SERVICE}")
174+
ngx.req.set_body_data(body)
175+
end
176+
}
177+
proxy_pass http://${MAILHOG_WEB_SERVICE}/;
178+
proxy_set_header Host ${MAILHOG_WEB_SERVICE};
179+
proxy_set_header X-Forwarded-Host $http_host;
180+
sub_filter_types application/json text/html;
181+
sub_filter "http://${MAILHOG_WEB_SERVICE}" "$scheme://$http_host";
182+
sub_filter_once off;
183+
}
184+
149185
location / {
150186
try_files $uri /index.html =404;
151187
add_header Last-Modified $date_gmt;

0 commit comments

Comments
 (0)