-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
56 lines (55 loc) · 1.95 KB
/
server.js
File metadata and controls
56 lines (55 loc) · 1.95 KB
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
const mockServer = require("mockttp").getLocal({
https: {
keyPath: "./certificates/key.key",
certPath: "./certificates/cert.pem",
},
});
const axios = require('axios').default;
mockServer
.start(80)
.then(() => {
console.log("Proxy available at " + mockServer.url);
mockServer
.forAnyRequest()
.always()
.thenCallback(async (req) => {
const url = new URL(req.url);
if (url.hostname == 'api-quiz.hype.space') {
console.log(req.url);
if (req.path.startsWith('/shows/schedule')) {
return {
json: {
shows: [],
announcements: []
}
}
} else {
// only necessary endpoints
if (
req.path.startsWith('/verifications')
|| req.path == '/usernames/available?'
|| req.path == '/referral-code/valid?'
|| req.path == '/users?'
|| req.path.startsWith('/terms-agreement/')
|| req.path == '/users/me'
) {
const response = await axios({
method: req.method,
url: `https://play.question.house${req.path}`,
headers: req.headers.authorization ? { Authorization: req.headers.authorization } : {},
data: await req.body.getJson(), // Forward request body
validateStatus: () => true // never throw due to the status code
});
return {
statusCode: response.status,
json: response.data // Send back the response body
};
}
}
}
return {};
});
})
.catch(err => {
console.log(err);
});