1 |
|
2 | 'use strict';
|
3 |
|
4 |
|
5 | var express = require('express');
|
6 | var socketio = require('socket.io');
|
7 | var config = require('otto-config');
|
8 | var response = require('otto-response');
|
9 |
|
10 |
|
11 | module.exports = function (options) {
|
12 |
|
13 | if (!options) { options = {}; }
|
14 |
|
15 |
|
16 | var app = express();
|
17 |
|
18 |
|
19 |
|
20 | var io = socketio();
|
21 | app.socketio = io;
|
22 |
|
23 |
|
24 | config.global(app, process.env, options);
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | app.disable('x-powered-by');
|
32 |
|
33 |
|
34 | app.use(function (req, res, next) {
|
35 | if (!req.locals) { req.locals = {}; }
|
36 | next();
|
37 | });
|
38 |
|
39 |
|
40 | if (options.routes) {
|
41 | if (!Array.isArray(options.routes)) { return new Error('options.routes needs to be an Array'); }
|
42 | for (var i = 0; i < options.routes.length; i++) {
|
43 | options.routes[i] (app);
|
44 | }
|
45 | }
|
46 |
|
47 |
|
48 | app.use(response.not_found);
|
49 |
|
50 |
|
51 | app.use(response.failure);
|
52 |
|
53 | return app;
|
54 |
|
55 | };
|