-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
60 lines (50 loc) · 1.61 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
var express = require('express'),
http = require('http'),
path = require('path'),
mongoose = require('mongoose'),
_ = require('underscore'),
config = require('./config');
// Bootstrap db connection
mongoose.connect(config.local_auth);
require('./models/trade');
var controllers = require('./controllers'),
trades = require('./controllers/trades');
/**
* App Configuration
*/
var app = module.exports = express();
app.set('port', process.env.PORT || 3000);
//views are pages that are rendered server-side
app.set('views', __dirname + '/views');
// remap html extension to the ejs engine
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.static(path.join(__dirname, 'static')));
app.use(app.router);
app.use(express.errorHandler());
/**
* Routes
*/
app.get('/', controllers.index);
app.get('/api/trades', trades.getAll);
app.get('/api/trades/:id', trades.getOne);
app.post('/api/trades', trades.create)
// app.get('*', routes.index);
// Test Data!!
var Trade = mongoose.model('Trade');;
var trade_fixture = require('./tests/fixture_trades.js').data;
Trade.find().remove();
_.each(trade_fixture, function(item){
var doc = new Trade(item);
doc.save();
});
/**
* All incoming requests to this port will be directed to the `app`. `app` is a function that when executed
* calls the first middleware in use and works it's way down the stack.
*/
http.createServer(app).listen(app.get('port'), function () {
console.log('Express server listening on port ' + app.get('port'));
});