/
app.js
39 lines (34 loc) · 1.07 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
36
37
38
39
const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser')
const fetch = require('node-fetch');
const app = express();
app.use(cors({
exposedHeaders: "Content-Length, X-JSON",
origin: 'https://akai-org.github.io'
}));
app.use(bodyParser.urlencoded({ extended: false }));
app.post("/*", (req, res, next) => {
if(req.body) {
let formBody = [];
for (const property in req.body) {
const encodedKey = encodeURIComponent(property);
const encodedValue = encodeURIComponent(req.body[property]);
formBody.push(encodedKey + "=" + encodedValue);
}
formBody = formBody.join("&");
fetch(`https://www.peka.poznan.pl/vm${req.url}`, {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: formBody
}).then(data => data.text())
.then(data => {
res.send(data);
})
.catch(err => {
console.warn(err);
res.send(400);
});
}
});
app.listen(5678, () => console.log('Amazing mega PEKA proxy listening on port 5678!'))