-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
48 lines (33 loc) · 1.07 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
var express = require('express'),
path = require('path'),
http = require('http'),
wordlist = require('./wordlist.json'),
app = express();
function globalErrorHandler(err, req, res, next) {
console.error('Unexpected ERROR: ' + err.stack);
res.send(500, 'Unexpected Error');
}
var env = process.env.NODE_ENV || 'development';
if ('development' == env) {
app.use(express.logger('dev'));
app.use(express.urlencoded());
//the middleware order matters that's why we use the rounting middleware before the static one
app.use(app.router);
//static middleware
app.use(express.static(path.join(__dirname, 'app')));
app.use(globalErrorHandler);
}
app.get('/*', function(req, res, next){
res.header('Access-Control-Allow-Origin', '*');
next();
});
app.get('/wordlist', function(req, res, next) {
res.send(wordlist);
});
app.post('/log/error', function(req, res) {
res.send(200);
});
app.set('port', process.env.PORT || 8998);
http.createServer(app).listen(app.get('port'), function(){
console.log(">> HTTP Server running - port " + app.get('port'));
});