-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
46 lines (35 loc) · 1.27 KB
/
server.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 bodyparser = require('body-parser');
var orm = require('./modules/orm');
var rest = require('./modules/rest');
var filterProcessors = require('./modules/rest/filterProcessors');
var initializer = require('./modules/initializer');
console.log(filterProcessors)
var sequelize = orm(process.env.DATABASE_URL);
var Transaction = sequelize.import(__dirname + '/models/transaction');
initializer.models(sequelize);
var transaction_rest = rest(sequelize, Transaction, {
filterProcessor: filterProcessors.transactions
});
var app = express();
var web = express.Router();
var rest = express.Router();
app.set('port', (process.env.PORT || 5000));
app.use(express.static(__dirname + '/public'));
app.use(bodyparser.urlencoded({extended: true}));
app.use(bodyparser.json());
// views is directory for all template files
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
web.get('/', function(request, response) {
response.render('pages/index');
});
rest.get('/hello', function(request, response) {
response.json({ message: "Hello world!" });
});
rest.use('/transactions', transaction_rest);
app.use('/', web);
app.use('/api', rest);
app.listen(app.get('port'), function() {
console.log('Node app is running on port', app.get('port'));
});