jam/src/setupProxy.js
Thebora Kompanioni 03e58c9059
feat: readd websocket connection (#122)
* feat: readd websocket connection

* add WebsocketProvider

* feat: update taker/maker state based on websocket data

* update connection indicator based on websocket state

* reconnect with linear backoff on websocket errors

the backend is not happy with a second instance in another browser tab
that send invalid tokens (e.g. because the previously used wallet was
locked in another tab). This introduces a linear increase to a max
of 10 seconds. Seems to ease the problem in the active tab.

* send keepalive message periodically

some webservers will close connections on inactivity rather
soon by default (e.g. nginx is 60s). this commit contains
sending a keepalive message periodically every 30 seconds.

Co-authored-by: d11n <mail@dennisreimann.de>
2022-02-28 13:23:44 +01:00

28 lines
778 B
JavaScript

const { createProxyMiddleware } = require('http-proxy-middleware')
module.exports = (app) => {
app.use(
createProxyMiddleware('/api/', {
target: 'https://localhost:28183',
changeOrigin: true,
secure: false,
ws: false,
onProxyReq: (proxyReq, req, res) => {
if (req.headers['x-jm-authorization']) {
proxyReq.setHeader('Authorization', req.headers['x-jm-authorization'])
}
},
})
)
// https://github.com/JoinMarket-Org/joinmarket-clientserver/blob/master/docs/JSON-RPC-API-using-jmwalletd.md#websocket
app.use(
createProxyMiddleware('/jmws', {
target: 'https://localhost:28283',
pathRewrite: { '^/jmws': '' },
changeOrigin: true,
secure: false,
ws: true,
})
)
}