-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
27 lines (23 loc) · 920 Bytes
/
Copy pathserver.js
File metadata and controls
27 lines (23 loc) · 920 Bytes
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
const http = require('http');
const port = process.env.PORT || 3000;
const base = 'https://treningskamp.ofdl.no';
const fallback = `${base}/`;
const rules = [
{ match: (path) => path === '/matches' || path.startsWith('/matches/'), target: `${base}/kamper` },
{ match: (path) => path === '/clubs/matches/new', target: `${base}/ny-kamp` },
{ match: (path) => path === '/login', target: `${base}/auth/login` },
{ match: (path) => path === '/admin/matches' || path.startsWith('/admin/matches/'), target: `${base}/admin/kamper` },
];
const resolve = (path) => {
const rule = rules.find((r) => r.match(path));
return rule ? rule.target : fallback;
};
http
.createServer((req, res) => {
const path = req.url.split('?')[0];
res.writeHead(301, { Location: resolve(path) });
res.end();
})
.listen(port, () => {
console.log(`Redirecting requests on port ${port}, fallback ${fallback}`);
});