-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.ts
More file actions
56 lines (44 loc) · 1.14 KB
/
app.ts
File metadata and controls
56 lines (44 loc) · 1.14 KB
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
import Koa from "koa";
import logger from 'koa-logger'
import fs from "fs";
import path from "path";
import cors from "koa2-cors";
import { serve } from "./src/httpRouter";
import config from "./src/config";
import { deleteFolderRecursive } from "./src/utils";
const app = new Koa();
console.log(`server vfile root is ${__dirname}`);
// 启动时清理rtspDir
const rtspDir = config.tempDir;
if (!fs.existsSync(rtspDir)) {
fs.mkdirSync(rtspDir);
}
if (fs.existsSync(rtspDir)) {
fs.readdirSync(rtspDir).forEach((file) => {
const curPath = path.join(rtspDir, file);
deleteFolderRecursive(curPath);
});
}
app.use(logger())
app.use(
cors({
origin: function (ctx) {
return ctx.request.header.origin;
},
credentials: true,
})
);
app.use(serve)
app.listen(config.port);
app.on("error", async (err, ctx) => {
console.error("error:", err);
});
console.log(`Server running on port ${config.port}`);
process.on('SIGTERM', () => {
console.log('SIGTERM signal received: closing HTTP server');
process.exit(0);
});
process.on('SIGINT', () => {
console.log('SIGINT signal received: closing HTTP server');
process.exit(0);
});