You just need to make sure your routes do not conflict with Swagger routes, and that your other routes will be processed as usual. One easy way is to make Swagger live under a subpath. Take a look at the documents on this subject:
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 can simply make sure that none of the other URLs that you use in your application conflict with Swagger URLs, and you should be able to define your routes and handlers normally. For instance. you can use Swagger to work with documents under http://localhost:8002/api-docs.json/pet , but http://localhost:8002/foo/ do something else by simply adding a route in the usual way:
app.get(/foo/, function(req, res, next) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello Foo\n'); })
Using a subdirectory configuration is probably the cleanest approach, but you can also simply track the routes yourself and make sure that Swagger routes do not conflict with the routes in the rest of your application.
source share