-
Notifications
You must be signed in to change notification settings - Fork 10
/
app.js
32 lines (27 loc) · 882 Bytes
/
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
var Stack = require('stack'),
Creationix = require('creationix'),
Path = require('path');
var missingSlash = new RegExp("^/([a-z_0-9-]+|[0-9]+\.[0-9]+\.[0-9]+)(/[a-z_0-9-]+)*$");
module.exports = Stack(
Creationix.postReceive("/post-receive", Path.join(__dirname, "/post-receive.sh")),
function (req, res, next) {
if (req.headers.host === "www.nodemanual.org") {
res.writeHead(301, {Location: "http://nodemanual.org" + req.url});
res.end();
return;
}
if (req.url === "/") {
res.writeHead(301, {Location: "/latest/"});
res.end();
return;
}
if (missingSlash.test(req.url)) {
res.writeHead(301, {Location: req.url + "/"});
res.end();
return;
}
next();
},
Creationix.static("/", Path.join(__dirname, "out/"), "index.html"),
Creationix.indexer("/", Path.join(__dirname, "out/"))
);