8000 use append_slash_redirect to redirect mailhog path request at root (#84) · localstack/localstack-extensions@81d1c94 · GitHub
[go: up one dir, main page]

Skip to content

Commit 81d1c94

Browse files
authored
use append_slash_redirect to redirect mailhog path request at root (#84)
1 parent 46c5779 commit 81d1c94

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

mailhog/mailhog/extension.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from localstack import config, constants
66
from localstack.extensions.api import Extension, http
7+
from werkzeug.utils import append_slash_redirect
78

89
try:
910
from localstack.pro.core import config as config_pro
@@ -81,6 +82,11 @@ def on_platform_ready(self):
8182
def update_gateway_routes(self, router: http.Router[http.RouteHandler]):
8283
endpoint = http.ProxyHandler(forward_base_url=self.server.url + "/" + self.server.web_path)
8384

85+
def _redirect_endpoint(request, *args, **kwargs):
86+
if not request.path.endswith("/"):
87+
return append_slash_redirect(request.environ)
88+
return endpoint(request, *args, **kwargs)
89+
8490
# hostname aliases
8591
router.add(
8692
"/",
@@ -97,11 +103,10 @@ def update_gateway_routes(self, router: http.Router[http.RouteHandler]):
97103
# useful, since the webapp needs to be accessed with a trailing slash (localhost:4566/<webpath>/)
98104
# otherwise the relative urls (like `images/logo.png`) are resolved as
99105
# `localhost:4566/images/login.png` which looks like an S3 access and will lead to localstack errors.
100-
# alas, we disabled this for good reason, so we're stuck with telling the user to add the trailing
101-
# slash.
106+
# alas, we disabled this for good reason, so we need to catch the request and redirect it if needed
102107
router.add(
103108
f"/{self.server.web_path}",
104-
endpoint=endpoint,
109+
endpoint=_redirect_endpoint,
105110
)
106111
router.add(
107112
f"/{self.server.web_path}/<path:path>",

0 commit comments

Comments
 (0)
0