app.js
1.18 KB
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
/**
* 展示服务
*/
var express = require('express');
var log4js = require('log4js');
var path = require('path');
log4js.loadAppender('file');
log4js.addAppender(log4js.appenders.file('web.log'), 'weblog');
var weblogger = log4js.getLogger('weblog');
weblogger.setLevel('INFO');
var log = log4js.connectLogger(weblogger);
var app = express();
app.use(log);
app.use(error);
app.use(express.static(path.join(__dirname, '../tests')));
app.map = function(a, route)
{
route = route || '';
for (var key in a)
{
switch (typeof a[key])
{
// { '/path': { ... }}
case 'object':
app.map(a[key], route + key);
break;
// get: function(){ ... }
case 'function':
app[key](route, a[key]);
break;
}
}
};
function gif(req, res)
{
var gif = "R0lGODlhAQABAID/AP///wAAACwAAAAAAQABAAACAkQBADs=";
var dataBuffer = new Buffer(gif, 'base64');
res.send(dataBuffer);
}
app.map(
{
'/ya.gif':
{
get : gif
}
});
function error(err, req, res, next)
{
syslog.error("error:"+err);
res.status(500);
res.send('Internal Server Error');
}
app.listen(8081, function() {
console.log('testserver at http://localhost:8081/');
});