-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
40 lines (32 loc) · 1.03 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
const express = require("express");
const app = express();
app.use(express.static("public"));
app.use(express.json());
const trackList = {};
const track_1 = require('./public/tracks/test.json');
trackList[1] = track_1;
app.get("/", (request, response) => {
response.sendFile(__dirname + "/public/index.html");
});
app.get("/editor", (request, response) => {
response.sendFile(__dirname + "/public/editor.html");
});
app.get("/intro", (request, response) => {
response.sendFile(__dirname + "/public/index.html");
});
app.post("/tracks", (request, response) => {
const track = request.body;
track.id = Date.now();
trackList[track.id] = track;
response.send(track);
});
app.get("/tracks", (request, response) => {
response.send(Object.values(trackList));
});
app.get("/tracks/:trackId", (request, response) => {
const trackId = request.params.trackId;
response.send(trackList[trackId]);
});
const listener = app.listen(process.env.PORT, () => {
console.log("TrackStar is listening on port " + listener.address().port);
});