From 054745537744087b4470bc41b0a203047ee4915c Mon Sep 17 00:00:00 2001 From: sodoku Date: Tue, 2 Apr 2019 22:12:27 +0200 Subject: [PATCH 1/2] Add proxy for cbeam rpc --- server/index.js | 2 ++ server/route/cbeamRpc.js | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 server/route/cbeamRpc.js diff --git a/server/index.js b/server/index.js index 4e3de82..1aac349 100644 --- a/server/index.js +++ b/server/index.js @@ -8,6 +8,7 @@ const path = require('path'); const routePictures = require('./route/pictures'); const route35c3 = require('./route/35c3'); const routeCalendar = require('./route/calendar'); +const routeCBeamRPC = require('./route/cbeamRpc'); const app = new Koa(); const router = new Router(); @@ -15,6 +16,7 @@ const router = new Router(); route35c3(router); routePictures(router); routeCalendar(router); +routeCBeamRPC(router); app .use(Cors()) diff --git a/server/route/cbeamRpc.js b/server/route/cbeamRpc.js new file mode 100644 index 0000000..32a4814 --- /dev/null +++ b/server/route/cbeamRpc.js @@ -0,0 +1,19 @@ +require('isomorphic-fetch'); + +module.exports = (router) => { + router.get('/rpc/:method', async (ctx) => { + const res = await fetch('http://c-beam.cbrp3.c-base.org:4254/rpc/', { + credentials: 'omit', + headers: { + 'content-type': 'application/json', + }, + body: `{"jsonrpc":"2.0","id":1550009052773,"method":"${ctx.params.method}","params":""}`, + method: 'POST', + mode: 'cors', + }); + // const res = await fetch('http://c-beam.cbrp3.c-base.org:4254/rpc/;, {"credentials":"omit","headers":{"content-type":"application/json"},"referrerPolicy":"no-referrer-when-downgrade","body":`{\"jsonrpc\":\"2.0\",\"id\":1550009052773,\"method\":\"${ctx.params.method}\",\"params\":\"\"}`,"method":"POST","mode":"cors"}); + ctx.assert((res.status === 200), res.status); + const body = await res.json(); + ctx.body = body; + }); +}; From 47c36be218c44767d1e2ad7107d82b855599b659 Mon Sep 17 00:00:00 2001 From: Philip Stewart Date: Thu, 4 Apr 2019 14:28:44 +0200 Subject: [PATCH 2/2] Remove comment --- server/route/cbeamRpc.js | 1 - 1 file changed, 1 deletion(-) diff --git a/server/route/cbeamRpc.js b/server/route/cbeamRpc.js index 32a4814..d9e759c 100644 --- a/server/route/cbeamRpc.js +++ b/server/route/cbeamRpc.js @@ -11,7 +11,6 @@ module.exports = (router) => { method: 'POST', mode: 'cors', }); - // const res = await fetch('http://c-beam.cbrp3.c-base.org:4254/rpc/;, {"credentials":"omit","headers":{"content-type":"application/json"},"referrerPolicy":"no-referrer-when-downgrade","body":`{\"jsonrpc\":\"2.0\",\"id\":1550009052773,\"method\":\"${ctx.params.method}\",\"params\":\"\"}`,"method":"POST","mode":"cors"}); ctx.assert((res.status === 200), res.status); const body = await res.json(); ctx.body = body;