Merge pull request #44 from c-base/matelight

Add matelight proxy
This commit is contained in:
Henri Bergius 2019-07-15 17:57:13 +02:00 committed by GitHub
commit 35ec4b6b8b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View file

@ -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())

19
server/route/matelight.js Normal file
View file

@ -0,0 +1,19 @@
require('isomorphic-fetch');
module.exports = (router) => {
router.post('/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.post('/matelight/:command/:argument', async (ctx) => {
console.log(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;
});
};