-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapp.js
35 lines (29 loc) · 1.01 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
var http = require('http'),
forwardings = require('./redirects');
http.createServer(function (req, res) {
var hostname = req.headers.host.replace(/:.*/, "");
url = req.url,
location = null;
// Find path under requested domain
if (typeof forwardings.url[hostname] != 'undefined') {
if (typeof forwardings.url[hostname][url] != 'undefined') {
location = forwardings.url[hostname][url];
}
}
// Find path under wildcard-domain
if (location == null && typeof forwardings.url['*'] != 'undefined') {
if (typeof forwardings.url['*'][url] != 'undefined') {
location = forwardings.url['*'][url];
}
}
// Find full domain redirect
if (location === null && typeof forwardings.domain[hostname] != 'undefined') {
location = forwardings.domain[hostname];
}
if (location !== null) {
res.writeHead(302, { 'Location': location });
return res.end();
}
res.writeHead(404);
res.end("Hostname -> URL does not found!");
}).listen(process.env.PORT || 5000);