-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (37 loc) · 1.1 KB
/
index.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
var express = require('express');
var mongoose = require('mongoose');
var bodyParser = require('body-parser');
var methodOverride = require('method-override');
var _ = require('lodash');
var app = express();
// Init Middleware
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
app.use(methodOverride('X-HTTP-Method-Override'));
//CORS
app.use(function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers', 'Content-Type');
next();
});
app.use('/hello', function(req, res, next) {
res.send('Hi !');
next();
});
// Connect MongoDB
mongoose.connect('mongodb://localhost/chinese');
mongoose.connection.once('open', function() {
// Loading models
app.models = require('./models/index');
// Loading routes
var routes = require('./routes');
_.each(routes, function(controller, route) {
app.use(route, controller(app, route));
});
// Running
console.log('Listening on 3894');
app.listen(3894);
});