Swagger-ui: How to dynamically set url in index.html?

Created on 9 Jul 2015  路  2Comments  路  Source: swagger-api/swagger-ui

I am deploying from two different servers, so how can I dynamically set the url in index.html? The documentation is static served from a Node.js server.

Node.js code
-------------
if (isThisServer) {
    urlFromNode = '/this';
} else {
    urlFromNode = '/that';
}

index.html
-------------
var swaggerUi = new SwaggerUi({
    url: urlFromNode,
});
swaggerUi.load();

Any suggestions? In every example I've just seen the url hardcoded. I'd rather not go through the hassle of setting up templating. I figure there would be an easier way to do this.

Most helpful comment

Don't know if this helps, but you can pass the url parameter to the index.html itself (like http://petstore.swagger.io?url=http://..../swagger.json. Otherwise, at least for now, I can't think of another way besides your own solution but others may have ideas.

All 2 comments

Don't know if this helps, but you can pass the url parameter to the index.html itself (like http://petstore.swagger.io?url=http://..../swagger.json. Otherwise, at least for now, I can't think of another way besides your own solution but others may have ideas.

Pass the ?url=http://petstore.swagger.io/v2/swagger.json or dynamically generate the index.html inside your app.

Was this page helpful?
0 / 5 - 0 ratings