-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
131 lines (110 loc) · 3.56 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*****************************************************************************
* Module dependencies.
*
*/
var fs = require('fs');
var Express = require('express');
var BodyParser = require('body-parser');
var MethodOverride = require('method-override');
var ErrorHandler = require('errorhandler');
var Layouts = require('express-ejs-layouts');
var engines = require('consolidate-build');
var app = module.exports = Express();
/*****************************************************************************
* Configuration
*
*/
var config = JSON.parse(fs.readFileSync(__dirname+ '/config.json', 'utf-8'));
/****************************
* Express.js Configuration
*
*/
app.set('port', process.env.PORT || config.server.port);
app.set('host', process.env.IP || config.server.host);
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.use(Layouts);
app.use(BodyParser.json());
app.use(BodyParser.urlencoded({extended:true}));
app.use(MethodOverride());
app.use(Express.static(__dirname + '/public'));
//app.engine('ejs', engines.ejs);
//app.engine('less', engines.less);
if (app.get('env') === 'development') {
app.use(ErrorHandler({ dumpExceptions: true, showStack: true }));
} else {
app.use(ErrorHandler());
}
/*****************************************************************************
* Errors
*
*/
function NotFound(msg, err) {
this.name = 'NotFound';
this.code = 404;
this.err = err;
Error.call(this, msg);
Error.captureStackTrace(this, arguments.callee);
}
NotFound.prototype.__proto__ = Error.prototype;
/*****************************************************************************
* Routes
*
*/
var sampleSendFileOpts = {
root: __dirname +'/samples/',
dofiles: 'deny'
};
app.get('/', function(req, res){
res.render('index', {
title: 'Summarization Viewer'
});
});
/* Map the URL '/samples/:id'
* to './samples/:id'
*/
app.get('/samples/:id', function(req, res, next){
var path = req.params.id;
res.sendFile(path, sampleSendFileOpts, function(err) {
if (err && err.code !== 'ECONNABORT') {
//next(new NotFound("Cannot locate sample '"+ path +"'", err));
console.error("*** Sample '%s': %s", path, err);
res.status(404).send( null );
/*
} else {
console.log(">>> transferred samples/%s", path);
// */
}
});
});
/* Map the URL '/samples/duc02/:set/:id'
* to './samples/duc02/keywords/single/:set/%id
*/
app.get('/samples/duc02/:set/:id', function(req, res, next){
var path = 'duc02/keywords/single/'
+ req.params.set +'/'+ req.params.id;
res.sendFile(path, sampleSendFileOpts, function(err) {
if (err && err.code !== 'ECONNABORT') {
//next(new NotFound("Cannot locate sample '"+ path +"'", err));
console.error("*** Sample '%s': %s", path, err);
res.status(404).send( null );
/*
} else {
console.log(">>> transferred samples/%s", path);
// */
}
});
});
/*****************************************************************************
* Start the server
*
*/
app.listen(app.get('port'), app.get('host'), function() {
var server = this;
console.log("Express server listening on %s:%d in %s mode",
server.address().address, server.address().port,
app.get('env'));
console.log(">>> The Earthquake example is at:");
console.log(" http://%s:%s/?duc02/d061j/AP880911-0016.html",
server.address().address, server.address().port);
});