-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
49 lines (41 loc) · 1.08 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 cors = require("cors");
const fetch = (...args) =>
import("node-fetch").then(({ default: fetch }) => fetch(...args));
const app = express();
app.use(cors());
app.use(express.json());
// Serve the public directory
app.use(express.static("public"));
// Serve the src directory
app.use("/src", express.static("src"));
var distDir = __dirname + "/dist/";
app.use(express.static(distDir));
const port = process.env.PORT || 4000;
app.listen(port, () => {
console.log(`listening on ${port}`);
});
app.get("/test", (req, res) => {
res.json({
message: "Behold The MEVN Stack!",
});
});
// Top playlists
app.get("/api/playlists/top/:limit", (req, res) => {
fetch(
"https://api.deezer.com/chart/0/playlists?limit=" + req.params.limit,
{}
)
.then((data) => data.json())
.then((json) => {
res.send(json);
});
});
// One playlist
app.get("/api/playlist/:id", (req, res) => {
fetch("https://api.deezer.com/playlist/" + req.params.id, {})
.then((data) => data.json())
.then((json) => {
res.send(json);
});
});