-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
36 lines (29 loc) · 964 Bytes
/
app.ts
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
import * as express from "express";
import * as errorHandler from "errorhandler";
import * as methodOverride from "method-override";
var bodyParser = require('body-parser');
import * as mongoose from 'mongoose';
import * as routes from "./server-src/routes/index";
import * as api from "./server-src/routes/api";
var app = express();
// Configuration
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(methodOverride());
app.use(express.static(__dirname + '/frontend'));
var env = process.env.NODE_ENV || 'development';
if (env === 'development') {
app.use(errorHandler());
}
var dbName = 'userDB';
mongoose.connect('mongodb://localhost/' + dbName);
// Routes
api.initRoutes(app);
app.get('/', routes.index);
app.get('/*', (req, res) => {
res.redirect('/');
});
app.listen(3000, function(){
console.log("Demo Express server listening on port %d in %s mode", 3000, app.settings.env);
});
export var App = app;