Skip to content

Commit 22f904e

Browse files
committed
Allow swagger-servant-ui with redoc to be nested in an API
In the current state, if we were to declare a servant-swagger-ui server behind some path, for instance: type API = "docs" :> ServantSwaggerUI "swagger-ui" "swagger.json" One would correctly have access to the template in `<host>/docs/swagger.ui` but the template would refer to a swagger.json at `/swagger.json` whereas it is hosted under `/docs/swagger.json`. To cope with this, we can use relative paths in the template, making sure that the current url is always ending with a slash.
1 parent fdb6106 commit 22f904e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

servant-swagger-ui-redoc/redoc.index.html.tmpl

+9-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,17 @@
77
<style>
88
body { margin: 0; padding: 0; }
99
</style>
10+
<script>
11+
// Force Strict-URL Routing for assets relative paths
12+
(function onload() {
13+
if (!window.location.href.endsWith("/")) {
14+
window.location.href += "/";
15+
}
16+
}());
17+
</script>
1018
</head>
1119
<body>
12-
<redoc spec-url='/SERVANT_SWAGGER_UI_SCHEMA'></redoc>
20+
<redoc spec-url='../SERVANT_SWAGGER_UI_SCHEMA'></redoc>
1321
<script src="redoc.min.js"> </script>
1422
</body>
1523
</html>

0 commit comments

Comments
 (0)