1 |
|
2 | 'use strict';
|
3 |
|
4 |
|
5 | var async = require('async');
|
6 | var express = require('express');
|
7 | var socketio = require('socket.io');
|
8 | var config = require('otto-config');
|
9 | var response = require('otto-response');
|
10 |
|
11 |
|
12 | module.exports = function (options) {
|
13 |
|
14 | if (!options) { options = {}; }
|
15 |
|
16 |
|
17 | var app = express();
|
18 |
|
19 |
|
20 | app.socketio = socketio();
|
21 |
|
22 |
|
23 | config.global(app, process.env, options);
|
24 |
|
25 |
|
26 | if (options.static) {
|
27 | app.use(express.static(options.static));
|
28 | }
|
29 |
|
30 |
|
31 | if (options.routes) {
|
32 | if (!Array.isArray(options.routes)) { return new Error('options.routes needs to be an Array'); }
|
33 | async.mapSeries(options.routes, function (route, done) {
|
34 | route(app, done);
|
35 | }, function (error) {
|
36 |
|
37 |
|
38 | app.use(response.not_found);
|
39 |
|
40 |
|
41 | app.use(response.failure);
|
42 |
|
43 | });
|
44 | }
|
45 |
|
46 | return app;
|
47 |
|
48 | };
|