Last active
December 31, 2015 06:39
-
-
Save d1b1/7949456 to your computer and use it in GitHub Desktop.
Express.js App for testing REST API (Swagger.js) on CodeShip.io
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment