-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
49 lines (39 loc) · 1.35 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
const express = require('express');
const fs = require('fs');
const fetch = require('cross-fetch');
const app = express();
const REDIRECT_URI = process.env.DEVELOPMENT
? 'http://localhost:4000'
: 'https://wowot.cc';
const APPLICATION_ID = fs.readFileSync('.token', 'utf8');
app.use(express.json());
app.get('/#', (req, res) => {
const realm = req.query.realm;
res.redirect(
`https://api.worldoftanks.${realm}/wot/auth/#/?application_id=${APPLICATION_ID}&expires_at=600&redirect_uri=${REDIRECT_URI}/authenticated/`
);
});
app.get('/logout', async (req, res) => {
const realm = req.query.realm;
const accessToken = req.query.access_token;
await fetch(
`https://api.worldoftanks.${realm}/wot/auth/logout/?application_id=${APPLICATION_ID}&access_token=${accessToken}`,
{ method: 'POST' }
);
res.redirect('/');
});
app.post('/time', async (req, res) => {
const { accessToken, accountId, realm } = req.body;
const json = await (
await fetch(
`https://api.worldoftanks.${realm}/wot/account/info/?application_id=350d62f4514e16a540067fa3750a3769&account_id=${accountId}&access_token=${accessToken}`
)
).json();
if (json.status === 'error' && json.error.code === 407) {
res.status(400).send({ error: true });
return;
}
res.status(200).send(json);
});
app.use('/', express.static('assets'));
app.listen(4000);