-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
63 lines (53 loc) · 1.58 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Bring in environment secrets through dotenv
require("dotenv/config");
// Use axios to make HTTP requests from Node
const axios = require("axios");
const path = require('path')
const fs = require("fs");
// Run the express app
const express = require("express");
const app = express();
app.use(express.static(path.join(__dirname, 'public')))
let access_token = "";
let scopes = "";
async function getAccessToken() {
try {
const response = await axios.post(
`https://zoom.us/oauth/token?grant_type=account_credentials&account_id=${process.env.account_id}`,
null,
{
auth: {
username: process.env.clientID,
password: process.env.clientSecret,
},
}
);
return response.data.access_token;
} catch (error) {
console.error("Error getting access token: ", error.message);
throw error;
}
}
app.get("/websocket", async (req, res) => {
try {
const acc = await getAccessToken();
// Read the HTML file
fs.readFile("public/index.html", "utf8", (err, data) => {
if (err) {
console.error(err);
res.status(500).send("Internal Server Error");
return;
}
// Replace the access token in the HTML code
data = data.replace("${access_token}", acc);
// Send the HTML code as the response
res.send(data);
});
} catch (error) {
console.error("Error handling request: ", error.message);
res.status(500).send("Internal Server Error");
}
});
app.listen(4000, () =>
console.log(`Zoom Hello World app listening at PORT: 4000`)
);