d1b1
12/13/2013 - 7:06 PM

Express.js App for testing REST API (Swagger.js) on CodeShip.io

Express.js App for testing REST API (Swagger.js) on CodeShip.io

/* 

  This script is part of a pattern that allows mocha to test 
  a REST API (Swagger.js + Expressjs) on a CI provider, codeship.io,
  travis-ci etc. This makes the express app accessible to script
  that starts the server and runs the tests.
  
  Also see: https://gist.github.com/d1b1/7949308 (Programmable Mocha script)

*/

/* Dependencies */ 

var express  = require('express')
var passport = require('passport')
var mongoose = require('mongoose')
var fs       = require('fs')

/* If needed define the Mongo and ES calls for the test env. */

process.env.MONGODB_URI="XXXXXXXXXXXXXXXXXXXX"
process.env.SEARCHBOX_URL="XXXXXXXXXXXXXXXXXXXX"

/* Tell Mongoose about its db. */

mongoose.connect(process.env.MONGODB_URI)

/* Set some path info */

var basePath = require('path').join(__dirname, '/../..')
var models_path = require('path').join(__dirname, '/../../app/models')

/* Bootstrap models */

fs.readdirSync(models_path).forEach(function (file) {
  if (~file.indexOf('.js')) require(models_path + '/' + file)
})

/* Create the express App */

var app = express()

/* Attach the different middleware elements */
require(basePath + '/config/passport')(passport)
require(basePath + '/config/express')(app, passport)
require(basePath + '/config/routes')(app, passport)

/* Export the App */

module.exports = app