-
Notifications
You must be signed in to change notification settings - Fork 0
/
param.js
34 lines (26 loc) · 956 Bytes
/
param.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
var path = require('path');
var express = require('express');
var bodyparser = require('body-parser');
var stylus = require('stylus');
var crypto = require('crypto');
var app = express();
app.use(bodyparser.urlencoded({extended: false}));
app.use(stylus.middleware(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, 'public')));
app.param('msgId', function (req, res, next, id) {
req.msgId = id;
return next();
});
app.set('view engine', 'jade');
app.set('views', path.join(__dirname, 'templates') );
app.get('/home', function(req, res) {
res.render('index', {date: new Date().toDateString()});
});
app.post('/form', function(req, res){
res.end(req.body.str.split('').reverse().join(''));
});
app.put('/message/:msgId', function(req, res){
var hash = crypto.createHash('sha1').update(new Date().toDateString() + req.msgId).digest('hex');
res.end(hash);
});
app.listen(app.listen(process.argv[2]));