-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
155 lines (125 loc) · 3.2 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
const express = require("express");
const axios = require("axios").default;
const bodyParser = require("body-parser");
const path = require("path");
const app = express();
const port = process.env.PORT || 3001;
app.use(bodyParser.json());
// enable CORS without external module
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept"
);
next();
});
app.use(express.static(path.join(__dirname)));
app.get("/", (req, res) => {
res.sendFile(path.join(__dirname, "../index.html"));
});
// Create a livestream
app.get("/create", (req, res) => {
const options = {
method: "POST",
url: "https://api.liveapi.com/live_streams",
headers: {
Accept: "application/json",
Authorization:
"Basic aGQxZ25OU2JkNzVnOmQ5M0ZEN3dTeEkzcjc5SnNtblQ3SWltRnllOUFERkw3a0FuNQ==",
},
};
axios
.request(options)
.then(function (response) {
let data = response.data;
res.send(data);
})
.catch(function (error) {
console.error(error);
});
});
app.get("/streams", (req, res) => {
const options = {
method: "GET",
url: "https://api.liveapi.com/live_streams",
headers: {
Accept: "application/json",
Authorization:
"Basic aGQxZ25OU2JkNzVnOmQ5M0ZEN3dTeEkzcjc5SnNtblQ3SWltRnllOUFERkw3a0FuNQ==",
},
};
axios
.request(options)
.then(function (response) {
res.send(response.data);
})
.catch(function (error) {
console.error(error);
});
});
app.get("/streams/:id", (req, res) => {
let id = req.params.id;
const options = {
method: "GET",
url: `https://api.liveapi.com/live_streams/${id}`,
headers: {
Accept: "application/json",
Authorization:
"Basic aGQxZ25OU2JkNzVnOmQ5M0ZEN3dTeEkzcjc5SnNtblQ3SWltRnllOUFERkw3a0FuNQ==",
},
};
axios
.request(options)
.then(function (response) {
res.send(response.data);
})
.catch(function (error) {
console.error(error);
});
});
app.patch("/streams/:id", (req, res) => {
let id = req.params.id;
const options = {
method: "PATCH",
url: `https://api.liveapi.com/live_streams/${id}`,
headers: {
Accept: "application/json",
"Content-Type": "application/json",
Authorization:
"Basic aGQxZ25OU2JkNzVnOmQ5M0ZEN3dTeEkzcjc5SnNtblQ3SWltRnllOUFERkw3a0FuNQ==",
},
data: { enabled: true },
};
axios
.request(options)
.then(function (response) {
res.send(response.data);
})
.catch(function (error) {
console.error(error);
});
});
app.delete("/streams/:id", (req, res) => {
let id = req.params.id;
const options = {
method: "DELETE",
url: `https://api.liveapi.com/live_streams/${id}`,
headers: {
Accept: "application/json",
Authorization:
"Basic aGQxZ25OU2JkNzVnOmQ5M0ZEN3dTeEkzcjc5SnNtblQ3SWltRnllOUFERkw3a0FuNQ==",
},
};
axios
.request(options)
.then(function (response) {
res.send(response.data);
})
.catch(function (error) {
console.error(error);
});
});
app.listen(port, () => {
console.log(`Server listeining at port ${port}`);
});