-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
41 lines (31 loc) · 1020 Bytes
/
index.js
File metadata and controls
41 lines (31 loc) · 1020 Bytes
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
const express = require("express");
const path = require("path");
require("dotenv").config();
const app = express();
app.use(express.json());
const clientId = process.env.CLIENT_ID;
const redirectUri = process.env.REDIRECT_URI;
app.use((req, res, next) => {
console.log(`${req.method} ${req.path}`);
next();
});
app.get("/", (req, res) => {
res.send("server is running.");
});
app.get("/auth", (req, res) => {
const scopes = [
"playlist-read-private",
"playlist-modify-public",
"playlist-modify-public",
];
const scopeString = scopes.join(" ");
const url = `https://accounts.spotify.com/authorize?client_id=${clientId}&redirect_uri=${encodeURIComponent(
redirectUri
)}&scope=${encodeURIComponent(scopeString)}&response_type=token`;
res.redirect(url);
});
app.get("/callback", (req, res) => {
res.sendFile(path.join(__dirname, "/index.html"));
});
const PORT = 5173;
app.listen(PORT, console.log(`Server listening on port ${PORT}`));