-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.js
59 lines (53 loc) · 1.78 KB
/
server.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const express = require("express");
const app = express();
const fetch = require("node-fetch");
const path = require("path");
require("dotenv").config();
const symblAppId = process.env.SYMBL_APP_ID;
const symblAppSecret = process.env.SYMBL_APP_SECRET;
const symblApiBasePath =
process.env.SYMBL_API_BASE_PATH || "https://api.symbl.ai";
const agoraAppId = process.env.REACT_APP_AGORA_APP_ID;
// const MAX_ALLOWED_SESSION_DURATION = 14400;
// app.use(express.static(path.join(__dirname, "build")));
app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept, X-API-KEY"
);
next();
});
app.get("/symbl-token", async (req, res) => {
try {
const response = await fetch(
`${symblApiBasePath}/oauth2/token:generate`,
{
method: "POST",
mode: "cors",
cache: "no-cache",
credentials: "same-origin",
headers: {
"Content-Type": "application/json"
},
redirect: "follow",
referrerPolicy: "no-referrer",
body: JSON.stringify({
type: "application",
appId: symblAppId,
appSecret: symblAppSecret
})
}
);
res.setHeader("Content-Type", "application/json");
res.json(await response.json()).end();
} catch (e) {
console.error("Error while issuing Symbl Token.", e);
res.status(401)
.json({
message: e.toString()
})
.end();
}
});
app.listen(8081, () => console.log("Agora token server running on 8081"));