From cef19a6ae562eb9385bcee8d6934fdf764139932 Mon Sep 17 00:00:00 2001 From: sodoku Date: Mon, 6 May 2019 20:33:01 +0200 Subject: [PATCH] Add matelight proxy --- server/index.js | 2 ++ server/route/matelight.js | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 server/route/matelight.js diff --git a/server/index.js b/server/index.js index 1aac349..66c5022 100644 --- a/server/index.js +++ b/server/index.js @@ -9,6 +9,7 @@ const routePictures = require('./route/pictures'); const route35c3 = require('./route/35c3'); const routeCalendar = require('./route/calendar'); const routeCBeamRPC = require('./route/cbeamRpc'); +const routeMatelight = require('./route/matelight'); const app = new Koa(); const router = new Router(); @@ -17,6 +18,7 @@ route35c3(router); routePictures(router); routeCalendar(router); routeCBeamRPC(router); +routeMatelight(router); app .use(Cors()) diff --git a/server/route/matelight.js b/server/route/matelight.js new file mode 100644 index 0000000..f0e7069 --- /dev/null +++ b/server/route/matelight.js @@ -0,0 +1,18 @@ +require('isomorphic-fetch'); + +module.exports = (router) => { + router.get('/matelight/:command', async (ctx) => { + const { command } = ctx.params; + const res = await fetch(`http://matelight.cbrp3.c-base.org/api/${command}`); + ctx.assert((res.status === 200), res.status); + const body = await res.json(); + ctx.body = body; + }); + router.get('/matelight/:command/:argument', async (ctx) => { + const { command, argument } = ctx.params; + const res = await fetch(`http://matelight.cbrp3.c-base.org/api/${command}/${argument}`); + ctx.assert((res.status === 200), res.status); + const body = await res.json(); + ctx.body = body; + }); +};