Skip to content

Commit

Permalink
use append_slash_redirect to redirect mailhog path request at root (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
bentsku authored Nov 17, 2024
1 parent 46c5779 commit 81d1c94
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions mailhog/mailhog/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
"/",
Expand All @@ -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/<webpath>/)
# 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}/<path:path>",
Expand Down

0 comments on commit 81d1c94

Please sign in to comment.