4
4
5
5
from localstack import config , constants
6
6
from localstack .extensions .api import Extension , http
7
+ from werkzeug .utils import append_slash_redirect
7
8
8
9
try :
9
10
from localstack .pro .core import config as config_pro
@@ -81,6 +82,11 @@ def on_platform_ready(self):
81
82
def update_gateway_routes (self , router : http .Router [http .RouteHandler ]):
82
83
endpoint = http .ProxyHandler (forward_base_url = self .server .url + "/" + self .server .web_path )
83
84
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
+
84
90
# hostname aliases
85
91
router .add (
86
92
"/" ,
@@ -97,11 +103,10 @@ def update_gateway_routes(self, router: http.Router[http.RouteHandler]):
97
103
# useful, since the webapp needs to be accessed with a trailing slash (localhost:4566/<webpath>/)
98
104
# otherwise the relative urls (like `images/logo.png`) are resolved as
99
105
# `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
102
107
router .add (
103
108
f"/{ self .server .web_path } " ,
104
- endpoint = endpoint ,
109
+ endpoint = _redirect_endpoint ,
105
110
)
106
111
router .add (
107
112
f"/{ self .server .web_path } /<path:path>" ,
0 commit comments