forked from demokratie-live/bundestag.io-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
60 lines (49 loc) · 1.59 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
const express = require("express");
const next = require("next");
var basicAuth = require("basic-auth-connect");
const request = require("request")
// require("./lib/parseOpenDataXml");
const dev = process.env.NODE_ENV !== "production";
const app = next({ dev });
const handle = app.getRequestHandler();
const PORT = process.env.PORT || 3000;
app
.prepare()
.then(() => {
const server = express();
server.get("/health-check", (req, res) => {
res.status(200).send("ok")
});
if (!dev) {
console.log("ADMIN_USER:", process.env.ADMIN_USER.replace(/./g, '*'))
console.log("ADMIN_PASSWORD:", process.env.ADMIN_PASSWORD.replace(/./g, '*'))
server.use(basicAuth(process.env.ADMIN_USER, process.env.ADMIN_PASSWORD));
}
server.all("/graphql", (req, res) => {
console.log("HOHO")
const url = process.env.BUNDESTAGIO_SERVER_URL;
return req.pipe(request({ qs: req.query, uri: url, headers: {
"bio-auth-token": process.env.BIO_EDIT_TOKEN
} }).on('error', function (err) {
console.info(err);
return res.sendStatus(400);
}))
.pipe(res);
})
server.get("/procedure/:id", (req, res) => {
const actualPage = "/procedure";
const queryParams = { id: req.params.id };
app.render(req, res, actualPage, queryParams);
});
server.get("*", (req, res) => {
return handle(req, res);
});
server.listen(PORT, err => {
if (err) throw err;
console.log(`> Ready on http://localhost:${PORT}`);
});
})
.catch(ex => {
console.error(ex.stack);
process.exit(1);
});