-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
42 lines (36 loc) · 1.13 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
const express = require("express");
const {port} = require("./config");
const controller = require("./controller");
const nocache = require("nocache");
const db = require("./db");
module.exports = () => {
const app = express();
app.route('/mirrors').all(nocache()).get(
async (req,res) => {res.json(controller.static_mirror_list)}
)
app.route('/status').all(nocache()).get(
async (req,res) => {res.json(await db.getStatus())}
)
app.route('/stop/:id').all(nocache()).get(
async (req,res) => {
controller.stop(req.params.id)
.then(()=>{res.json({"status":"ok"})})
}
)
app.route('/start/:id').all(nocache()).get(
async (req,res) => {
if (await db.exists(req.params.id)) {
controller.start(req.params.id)
.then(()=>{res.json({"status":"ok"})})
}
}
)
app.route('/log/:id').all(nocache()).get(
async (req,res) => {
res.sendFile(await db.get('logPath',req.params.id))
}
)
app.listen(port, () => {
console.log(`Sync Master listening on ${port}`)
})
}