-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
54 lines (41 loc) · 1.16 KB
/
app.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
import express from 'express';
import cors from 'cors';
import cookieParser from 'cookie-parser';
import spotirank from './spotirank.js';
import { IP_ADDRESS } from './config.js';
const app = express()
.use(express.static('../public'))
.use(cors())
.use(cookieParser());
let userInSession = false;
app.get("/login", function (req, res) {
if (userInSession) {
res.redirect(`/#?error=${"This app is currently in use by another user"}`);
return;
}
res.redirect(spotirank.GetLoginUrl());
});
app.get("/callback", async function (req, res) {
if (userInSession) {
res.redirect(`/#?error=${"This app is currently in use by another user"}`);
return;
}
const code = req.query.code;
if (!(await spotirank.IsValidLogin(code))) {
res.redirect(`/#?error=${"Invalid login attempt"}`);
return;
}
userInSession = true;
await spotirank.Start();
});
app.get("/logout", function (req, res) {
if (!userInSession) {
res.redirect(`/#?error=${"A user must be signed in to logout"}`);
return;
}
userInSession = false;
spotirank.Stop();
res.redirect("/");
});
app.listen(8888, IP_ADDRESS);
console.log("Server started on port 8888");