forked from abelaska/nodejs-emberjs-mongodb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
66 lines (52 loc) · 1.29 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
/*global console:false, __dirname:false, process:false */
/**
* Module dependencies.
*/
var requirejs = require('requirejs');
requirejs.config({
nodeRequire: require
});
requirejs([
'express',
'mongoose',
'server/api/authors'
], function(
express,
mongoose,
api_authors
){
"use strict";
// connect to MongoDB
mongoose.connect('mongodb://localhost/example');
var app = express();
app.configure(function(){
app.use(express.favicon());
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
});
app.configure('development', function(){
app.use(express.logger('dev'));
app.use(express['static'](__dirname + '/client'));
app.use(express.errorHandler({
dumpExceptions: true,
showStack: true
}));
});
app.configure('production', function(){
// build client if directory client-build not found
var path = require('path');
if (!path.existsSync("client-build")) {
require('./build');
}
app.use(express['static'](__dirname + '/client-build'));
});
// ROUTES
app.get('/api/authors', api_authors.getAll);
app.del('/api/authors/:id', api_authors.remove);
app.post('/api/authors', api_authors.create);
// HTTP
var port = process.env.PORT || 3000;
app.listen(port);
console.log("Http server listening on port 3000");
});