-
Notifications
You must be signed in to change notification settings - Fork 0
/
maintenanceRequest.js
45 lines (40 loc) · 1.27 KB
/
maintenanceRequest.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
var url = require('url'),
fs = require('fs'),
http = require('http');
var defaultMessage = [
'<html><body>',
'Maintenance, please stand by',
'</body></html>'
].join('');
var mod = function(options) {
return function(request, response) {
fs.exists(options.maintenanceMessageFile, function(fexist) {
if (fexist) {
return respondeWithMaintFile();
} else {
return respondeWithoutMaintFile();
}
});
function respondeWithMaintFile() {
fs.readFile(options.maintenanceMessageFile, 'utf8', function(err, data) {
if (err) {
return respondeWithoutMaintFile();
} else {
response.writeHead(200, {
'Content-Length': data.length,
'Content-Type': 'text/html'
});
return response.end(data);
}
});
}
function respondeWithoutMaintFile() {
response.writeHead(200, {
'Content-Length': defaultMessage.length,
'Content-Type': 'text/html'
});
return response.end(defaultMessage);
}
};
};
module.exports = mod;