Skip to content

Commit 35ec4b6

Browse files
authored
Merge pull request #44 from c-base/matelight
Add matelight proxy
2 parents 49a4046 + 1a5778f commit 35ec4b6

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

server/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const routePictures = require('./route/pictures');
99
const route35c3 = require('./route/35c3');
1010
const routeCalendar = require('./route/calendar');
1111
const routeCBeamRPC = require('./route/cbeamRpc');
12+
const routeMatelight = require('./route/matelight');
1213

1314
const app = new Koa();
1415
const router = new Router();
@@ -17,6 +18,7 @@ route35c3(router);
1718
routePictures(router);
1819
routeCalendar(router);
1920
routeCBeamRPC(router);
21+
routeMatelight(router);
2022

2123
app
2224
.use(Cors())

server/route/matelight.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
require('isomorphic-fetch');
2+
3+
module.exports = (router) => {
4+
router.post('/matelight/:command', async (ctx) => {
5+
const { command } = ctx.params;
6+
const res = await fetch(`http://matelight.cbrp3.c-base.org/api/${command}`);
7+
ctx.assert((res.status === 200), res.status);
8+
const body = await res.json();
9+
ctx.body = body;
10+
});
11+
router.post('/matelight/:command/:argument', async (ctx) => {
12+
console.log(ctx)
13+
const { command, argument } = ctx.params;
14+
const res = await fetch(`http://matelight.cbrp3.c-base.org/api/${command}/${argument}`);
15+
ctx.assert((res.status === 200), res.status);
16+
const body = await res.json();
17+
ctx.body = body;
18+
});
19+
};

0 commit comments

Comments
 (0)