Skip to content

Commit 9016629

Browse files
committed
Added server files
1 parent 7b59b15 commit 9016629

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

proxy.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const { createProxyMiddleware } = require('http-proxy-middleware');
2+
3+
module.exports = function(app) {
4+
app.use(
5+
'/sandbox',
6+
createProxyMiddleware({
7+
target: 'https://api.sandbox.settle.eu/',
8+
changeOrigin: true,
9+
pathRewrite: {'^/sandbox' : ''}
10+
})
11+
);
12+
app.use(
13+
'/prod',
14+
createProxyMiddleware({
15+
target: 'https://api.settle.eu/',
16+
changeOrigin: true,
17+
pathRewrite: {'^/prod' : ''}
18+
})
19+
);
20+
};

server.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const express = require('express');
2+
const proxy = require('./proxy');
3+
const short = require('short-uuid');
4+
const path = require('path');
5+
const app = express();
6+
const { json } = require('body-parser');
7+
8+
console.log('Serving static asserts from .')
9+
app.use(express.static(path.join(__dirname, '.')));
10+
app.use(json({type: 'application/vnd.mcash.api.merchant.v1+json'}));
11+
12+
proxy(app);
13+
14+
const history = [];
15+
16+
app.get('/callback', function(req, res) {
17+
const id = short.generate();
18+
console.log('-------------------------')
19+
console.log(id);
20+
console.log('Serving request for history')
21+
22+
res.json({ "callback_history": history.slice(0, 10) });
23+
});
24+
25+
app.post('/callback', function(req, res) {
26+
const id = short.generate();
27+
console.log('-------------------------')
28+
console.log(id);
29+
console.log(req.method, req.url)
30+
console.log(req.headers)
31+
console.log(req.body);
32+
33+
history.unshift({id, body: req.body})
34+
35+
res.sendStatus(200);
36+
});
37+
38+
app.get('/*', function (req, res) {
39+
res.sendFile(path.join(__dirname, '.', 'index.html'));
40+
});
41+
42+
const port = 3000
43+
console.log(`Listening to 0.0.0.0:${port}`)
44+
app.listen(port);

0 commit comments

Comments
 (0)