-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
64 lines (56 loc) · 1.62 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
/*
* Module dependencies
*/
var express = require('express');
var stylus = require('stylus');
var nib = require('nib');
var path = require('path');
var http = require('http');
var fs = require('fs');
var crypto = require('crypto');
var md5 = require('md5');
//creating the app
var app = express();
//using the modules stylus and nib
function compile(str, path) {
return stylus(str).set('filename', path).use(nib());
}
//configuring app pointing to the views
app.configure(function() {
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.set('view options', {
layout: false
});
app.use(express.logger('dev'));
app.use(stylus.middleware({
src: __dirname + '',
compile: compile
}));
app.use(express.static(__dirname));
//Parser for POST requests, use req.body
app.use(express.bodyParser());
});
//For gravatar images
//hash md5
var pictureHash = md5(process.env.EMAIL_ADDRESS);
var sharecode = process.env.EMAIL_ADDRESS;
app.set('port', (process.env.PORT || 5000));
//server responses, aka Routes
app.get('/', function(req, res) {
res.render('index', {
title: 'Home',
picHash: pictureHash,
sharecode: sharecode
});
});
app.post('/message', function(req, res, next){
console.log(req.body);
res.set({'Content-Type': 'application/json'});
//the json object turned back into serialized form so have to
//stringify it again, then send it back
res.send('messageCB(\''+JSON.stringify(req.body)+'\')');
});
app.listen(app.get('port'), function() {
console.log('Node app is running on port', app.get('port'));
});