diff --git a/mailhog/mailhog/extension.py b/mailhog/mailhog/extension.py index 2347086..fd7e8d2 100644 --- a/mailhog/mailhog/extension.py +++ b/mailhog/mailhog/extension.py @@ -4,6 +4,7 @@ from localstack import config, constants from localstack.extensions.api import Extension, http +from werkzeug.utils import append_slash_redirect try: from localstack.pro.core import config as config_pro @@ -81,6 +82,11 @@ def on_platform_ready(self): def update_gateway_routes(self, router: http.Router[http.RouteHandler]): endpoint = http.ProxyHandler(forward_base_url=self.server.url + "/" + self.server.web_path) + def _redirect_endpoint(request, *args, **kwargs): + if not request.path.endswith("/"): + return append_slash_redirect(request.environ) + return endpoint(request, *args, **kwargs) + # hostname aliases router.add( "/", @@ -97,11 +103,10 @@ def update_gateway_routes(self, router: http.Router[http.RouteHandler]): # useful, since the webapp needs to be accessed with a trailing slash (localhost:4566//) # otherwise the relative urls (like `images/logo.png`) are resolved as # `localhost:4566/images/login.png` which looks like an S3 access and will lead to localstack errors. - # alas, we disabled this for good reason, so we're stuck with telling the user to add the trailing - # slash. + # alas, we disabled this for good reason, so we need to catch the request and redirect it if needed router.add( f"/{self.server.web_path}", - endpoint=endpoint, + endpoint=_redirect_endpoint, ) router.add( f"/{self.server.web_path}/",