This repository has been archived by the owner on Mar 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
server.js
58 lines (47 loc) · 1.46 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
50
51
52
53
54
55
56
57
58
const PORT = 5050;
const koa = require("koa");
const router = require("koa-router")();
const bodyParser = require("koa-bodyparser");
const xmlParser = require("koa-xml-body");
const path = require("path");
const http = require("http");
const musicAPI = require(path.resolve("src", "index.js"));
let app = new koa();
app.use(xmlParser());
app.use(bodyParser());
router.get("/search/song", async (ctx, next) => {
let response = await musicAPI.searchSong(ctx.request.query);
ctx.response.body = response;
return;
});
router.post("/search/song", async (ctx, next) => {
let response = await musicAPI.searchSong(ctx.request.body);
ctx.response.body = response;
return;
});
router.get("/get/song", async (ctx, next) => {
let response = await musicAPI.getSong(ctx.request.query);
ctx.response.body = response;
return;
});
router.post("/get/song", async (ctx, next) => {
let response = await musicAPI.getSong(ctx.request.body);
ctx.response.body = response;
return;
});
router.get("/get/comment", async (ctx, next) => {
let response = await musicAPI.getComment(ctx.request.query);
ctx.response.body = response;
return;
});
router.post("/get/comment", async (ctx, next) => {
let response = await musicAPI.getComment(ctx.request.body);
ctx.response.body = response;
return;
});
app.use(router.routes());
app.use(async (ctx, next) => {
ctx.status = 404;
});
http.createServer(app.callback()).listen(PORT);
console.log("music-api started at port " + PORT);