Using Swagger for Express alongside normal routes Using Swagger for Express alongside normal routes express express

Using Swagger for Express alongside normal routes


You'll just need to make sure that your routes don't conflict with the Swagger routes, and your other routes will processed as usual. One easy way would be to make Swagger live under a subpath. Take a look at the docs on that score:

https://github.com/wordnik/swagger-node-express

var app = express();var subpath = express();app.use(express.bodyParser());app.use("/v1", subpath);swagger.setAppHandler(subpath);

Otherwise, you could just keep an eye out to make sure that none of the other URLs you are using in your application conflict with the Swagger URLs, and you should be able to define your routes and handlers normally. E.g. you can use Swagger to serve up docs under http://localhost:8002/api-docs.json/pet but have http://localhost:8002/foo/ do something else just by adding the route in the normal way:

app.get(/foo/, function(req, res, next) {  res.writeHead(200, {'Content-Type': 'text/plain'});  res.end('Hello Foo\n');})

Using the subpath configuration is probably the cleanest approach but you could also just keep track of the routes yourself and make sure that the Swagger routes aren't conflicting with the routes in the rest of your app.