-
-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Subfolder OpenAPI UI #80
Comments
Interesting issue, I'll see what I can do |
Ok, I dug in a bit more, and I believe this is, at the end of the day, a limitation of Stoplight itself, not Fuego :) I can mostly get it to work by adjusting the Just for sharing what I'd done, here is the custom UIHandler I had to get it to where it semi-works today: func StoplightDocs(specURL string) http.Handler {
uiPath := BaseUIPath
if BaseUIPath == "" {
uiPath = "/"
}
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
_, _ = w.Write([]byte(`<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="referrer" content="same-origin" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>API Documentation</title>
<script src="https://unpkg.com/@stoplight/elements/web-components.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/@stoplight/elements/styles.min.css" />
</head>
<body style="height: 100vh;">
<elements-api
basePath="` + uiPath + `"
apiDescriptionUrl="` + BaseUIPath + specURL + `"
layout="responsive"
router="history"
logo="https://go-fuego.github.io/fuego/img/logo.svg"
tryItCredentialsPolicy="same-origin"
/>
</body>
</html>`))
})
} Using the above, the docs load behind the sub-folder, but the URL gets re-written, so subsequent updates to the page/URL end up breaking. I access: http://<load-balancer/proxy.fqdn>/fancy-app/api/docs Browser's URL gets updated to be: http://<load-balancer/proxy.fqdn>/api/docs All that said, I'll close this one out in favor of working w/ Stoplight folks upstream :) Until then, I now better understand how I can get some other API docs up for now. |
Nice catch! Happy to see that the possibility of using a custom UIHandler is really useful for some use cases. |
Is your feature request related to a problem? Please describe.
When I run my application behind a proxy, in lower environments, I access the API via a subfolder route. In this case, there is a proxy/router in between me and the application.
Example Config
Running this locally, works as expected since there is not a load balancer/proxy fronting the requests.
Using the same config behind the proxy, I'd make open the docs at the following URL.
http://<load-balancer/proxy.fqdn>/fancy-app/api/docs
When I do this, seems like the UI (at index.html) redirects the browser to the following:
http://<load-balancer/proxy.fqdn>/api/docs
Obviously, this ends w/ a 404 since the load-balancer/proxy is not aware of the
/api/docs
route.Describe the solution you'd like
I'd like to be able to have the API docs load when behind the load-balancer/proxy without much fuss :)
Describe alternatives you've considered
Looking around a little bit, it seems that there is a
fuego.WithBasePath()
func, but setting that must be setting something else as it doesn't appear to be honored in this context.Seems like the
fuego.WithBasePath()
doesn't inject it's value into theindex.html
template to the value ofbasePath
- See docsMight be helpful to allow passing that value in and maybe even choosing a different
router
type (in this case,history
may be helpful)?Additional context
N/A
The text was updated successfully, but these errors were encountered: