44
55from localstack import config , constants
66from localstack .extensions .api import Extension , http
7+ from werkzeug .utils import append_slash_redirect
78
89try :
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