-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (31 loc) · 816 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// @ts-check
import express from 'express';
import bodyParser from 'body-parser';
import { getBackendKey, getLoginToken } from './encrypt';
const app = express();
app.use(bodyParser.json());
const handleError = async (fn, res) => {
try {
await fn();
} catch (e) {
console.error({ error: e })
res.status(400);
res.json({ error: e.message });
}
};
app.post('/let-me-in', async (req, res) => {
handleError(async () => {
console.log({ body: req.body })
const backendKey = await getBackendKey(req.body || {});
res.json(backendKey);
}, res);
});
app.post('/login', async (req, res) => {
handleError(async () => {
console.log({ body: req.body })
const { token } = await getLoginToken(req.body || {});
res.json({ token });
}, res);
});
// @ts-ignore
app.listen();