-
Notifications
You must be signed in to change notification settings - Fork 224
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
Is there any way to configure utoipa behind reverse proxy? #842
Comments
Hi, I've also run into the same issue, but found a workaround. My setup: Axum server running behind Reverse Proxy, with URL rewrite: "/api" -> "/" struct PathPrefixAddon;
impl Modify for PathPrefixAddon {
fn modify(&self, openapi: &mut utoipa::openapi::OpenApi) {
match env::var("PATH_PREFIX") {
Ok(prefix) => openapi.servers = Some(vec![Server::new(prefix)]),
Err(_) => ()
}
}
}
async fn main() {
#[derive(OpenApi)]
#[openapi(modifiers(&PathPrefixAddon))]
struct ApiDoc;
let app = Router::new()
.merge(SwaggerUi::new("/docs").config(Config::new(["openapi.json"])).url("/docs/openapi.json", ApiDoc::openapi()));
} The The Note that there are other pitfalls to this setup:
|
Hi @plang-arista, thanks for your workaround. I can confirm it also works for the Swagger UI part when loading openapi.json on Actix-web, the next problem I am facing is the "Try it out" part still using the wrong endpoint. for example, my server is http://www.abcd.com/, set Apache reverse proxy to http://www.abcd.com/rusttest/ for Rust Actix-web Could you please help to see what's wrong in my code? thanks heaps
|
Hi, this is weird, this should work. Can you add logging that you have set your In the swagger page you should see a new Drop-Down select, labelled "Servers" with single value If that variable is also properly set up, I'm not sure how to go on. |
Thanks for the reply. For the current swagger page, it didn't show Drop-Down select, labelled "Servers" with single value /rusttest/. So might be env var problem. |
Hi @plang-arista, after I correctly set |
The workaround given will not fix the problem with trailing slash redirect from utoipa/utoipa-swagger-ui/src/axum.rs Line 52 in 4d798bc
thus if the API is available under prefix |
Yeah, I've covered that in:
This is what I have in my nginx reverse proxy to handle that:
|
OpenAPI supports servers but reverse proxy could be configured independently for a particular service sitting behind that proxy.
utoipa
has support for servers but it looks like the traitModify
is static. Is there some way to use X-Forwarded headers like for example it's done in domaindrivendev/Swashbuckle.AspNetCore#1801 ?The text was updated successfully, but these errors were encountered: