-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js~
67 lines (56 loc) · 1.86 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
var express = require('express')
,logger = require('morgan')
,path = require('path')
,errorHandler = require('errorhandler')
,mongoose = require('mongoose')
,stylus = require('stylus');
/*var favicon = require('serve-favicon');*/
var env = process.env.NODE_ENV = process.env.NODE_ENV || 'development';
var bodyParser = require('body-parser');
var app = express();
function compile(str,path){
return stylus(str).set('filename',path);
}
// all environments
app.set('views', path.join(__dirname, '/server/views'));
app.set('view engine', 'jade');
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(stylus.middleware(
{
src:__dirname + 'public',
compile: compile
}
));
app.use(express.static(path.join(__dirname, 'public')));
//mongoose.connect('mongodb://localhost/multivision');
mongoose.connect('mongodb://jeeames:multivision@ds041140.mongolab.com:41140/miltivision');
var db = mongoose.connection;
db.on('error', console.error.bind(console,'connection error...'));
db.once('open',function(callback){
console.log('db opened');
});
var messageSchema = mongoose.Schema({message:String});
var Message = mongoose.model('messages',messageSchema);
var mongoMessage;
Message.findOne().exec(function(err,messageDoc){
mongoMessage = messageDoc.message;
console.log(messageDoc.message);
});
// development only
if ('development' == app.get('env')) {
app.use(errorHandler());
}
app.get('/partials/:partialPath',function(req,res){
res.render('partials/' + req.params.partialPath);
});
app.get('*',function(req,res){
res.render('index',{ mongoMessage: mongoMessage });
});
/*app.get('/', routes.index);
app.get('/users', user.list);*/
var port = 3000;
app.listen(process.env.PORT || port, function(){
console.log('Express server listening on port ' + app.get('port'));
});