SHARE
TWEET

Untitled

a guest Aug 22nd, 2017 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict';
  2.  
  3. var SwaggerExpress = require('swagger-express-mw');
  4. var app = require('express')();
  5.  
  6. var mongoose = require('mongoose');
  7. var uri_db = 'mongodb://localhost:27017/test';
  8. mongoose.connect(uri_db,  {useMongoClient: true});
  9. console.log("Database Connection status: " + mongoose.connection.readyState);
  10.  
  11. module.exports = app; // for testing
  12.  
  13. var config = {
  14.   appRoot: __dirname // required config
  15. };
  16.  
  17. SwaggerExpress.create(config, function(err, swaggerExpress) {
  18.   if (err) { throw err; }
  19.  
  20.   // install middleware
  21.   swaggerExpress.register(app);
  22.  
  23.   var port = process.env.PORT || 10010;
  24.   app.listen(port);
  25.  
  26.   if (swaggerExpress.runner.swagger.paths['/hello']) {
  27.     console.log('try this:\ncurl http://127.0.0.1:' + port + '/hello?name=Scott');
  28.   }
  29. });
RAW Paste Data
Top