-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
69 lines (56 loc) · 2.3 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
This is the entry point for the Express app; it's invoked
from `/bin/www`
*/
var nconf = require('nconf').argv().env()
if(process.env.NODE_ENV === 'unittest')
nconf.file('env/unittest.json');
else if (process.env.NODE_ENV === 'travis')
nconf.file('env/travis.json');
else if (process.env.NODE_ENV === 'development')
nconf.file('env/development.json');
var mongoose = require('mongoose');
nconf = require('nconf')
mongoose.connect(nconf.get('mongooseURI'));
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var bodyParser = require('body-parser');
var app = express();
// configure app to use bodyParser()
// this will let us get the data from a POST
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
// Makes the generated html easier to read
app.locals.pretty = true;
// View engine setup. Jade has now been renamed Pug. The view engine generates
// the actual html our Jade/Pug templates. Only the error page is actually
// rendered on the server (Express) side; the rest is generated by the client
// application (e.g. Angular or React).
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
// Indicate the middleware that Express should use
app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
// The `public` folder will contain the files that need to be accessed
// by the client app (e.g. Angular .js files).
app.use(express.static(path.join(__dirname, 'public')));
var port = process.env.PORT || 8081; // set our port
// ROUTES FOR OUR API
// =============================================================================
var router = express.Router(); // get an instance of the express Router
// more routes for our API will happen here
// REGISTER OUR ROUTES -------------------------------
// all of our routes will be prefixed with /api
app.use('/api', app.router);
require('./src/routes/')(app);
// For any other routes, set the status to 404 and forward to error handler
/*app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});*/
// START THE SERVER
// =============================================================================
app.listen(port);
console.log('Magic happens on port ' + port);
module.exports = app;