This repository has been archived by the owner on Jul 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
executable file
·74 lines (64 loc) · 2.28 KB
/
server.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
65
66
67
68
69
70
71
72
73
74
const express = require('express');
const next = require('next');
const qs = require('qs');
const { NODE_ENV, ENV } = process.env;
const dev = typeof NODE_ENV === 'undefined' || NODE_ENV === 'development';
const app = next({ dev });
const handle = app.getRequestHandler();
const http_port = process.env.PORT || 7001;
const root_url_prefix = ENV === 'kubernetes' ? '/runregistry' : '';
app.prepare().then(() => {
const server = express();
// We set depth of query parser to allow complicated url filters on the table (for bookmarkability)
server.set('query parser', function (str) {
return qs.parse(str, { depth: 50 });
});
// const router = express.Router();
// Redirects primary url to runs/all
server.get('/', (req, res) => {
res.redirect(`${root_url_prefix}/online/global`);
});
server.get('/online', (req, res) => {
res.redirect(`${root_url_prefix}/online/global`);
});
server.get('/offline', (req, res) => {
res.redirect(`${root_url_prefix}/offline/datasets/global`);
});
//online:
server.get('/online/:workspace', (req, res) => {
req.params.type = 'online';
const params = { ...req.headers, ...req.params, filters: req.query };
app.render(req, res, `/online`, params);
});
// offline:
// section can be either datasets or cycles
server.get('/offline/:section/:workspace', (req, res) => {
req.params.type = 'offline';
const params = { ...req.headers, ...req.params, filters: req.query };
app.render(req, res, `/offline`, params);
});
// json:
server.get('/json', (req, res) => {
req.params.type = 'json';
const params = { ...req.headers, ...req.params, filters: req.query };
app.render(req, res, `/json`, params);
});
server.get('/json_portal', (req, res) => {
req.params.type = 'json_portal';
const params = { ...req.headers, ...req.params, filters: req.query };
app.render(req, res, `/json_portal`, params);
});
// log:
server.get('/log', (req, res) => {
req.params.type = 'log';
const params = { ...req.headers, ...req.params, filters: req.query };
app.render(req, res, `/log`, params);
});
server.get('*', (req, res) => {
return handle(req, res);
});
server.listen(http_port, (err) => {
if (err) throw err;
console.log(`> HTTP listening in port ${http_port}`);
});
});