forked from NezbiT/nodester
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoffline.js
64 lines (50 loc) · 1.35 KB
/
offline.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
#!/usr/bin/env node
/*
Nodester opensource Node.js hosting service
Written by: @_alejandromg
http://nodester.com
*/
var express = require('express'),
url = require('url'),
sys = require('sys'),
config = require('./config'),
middle = require('./lib/middle');
process.on('uncaughtException', function (err) {
console.log(err.stack);
});
// daemon.setreuid(config.opt.userid);
var myapp = express.createServer();
myapp.configure(function () {
myapp.use(express.bodyParser());
myapp.use(express.static(__dirname+'/public/images'));
myapp.use(express.errorHandler({
showStack: true,
dumpExceptions: true
}));
});
// Error handler
myapp.error(function (err, req, res, next) {
if (err instanceof NotFound) {
res.sendfile(__dirname + '/public/404.html');
} else {
res.sendfile(__dirname + '/public/500.html');
}
});
/* Routes */
myapp.all('*',function(req,res,next){
res.sendfile(__dirname+'/public/offline.html');
})
myapp.all('/images/*',function(req,res){
res.sendfile(__dirname+'/public/'+req.url);
})
myapp.get('/',function(req,res){
res.sendfile(__dirname+'/public/offline.html');
})
// Homepage
myapp.listen(4001);
console.log('Nodester mainteinance app started on port 4001');
function NotFound(msg) {
this.name = 'NotFound';
Error.call(this, msg);
Error.captureStackTrace(this, arguments.callee);
};