-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
53 lines (45 loc) · 1.15 KB
/
server.js
File metadata and controls
53 lines (45 loc) · 1.15 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
require('colors');
const http = require('http');
const koa = require('koa');
const koaBody = require('koa-body');
const router = require('./routes');
const fs = require('fs');
const path = require('path');
const tempPath = path.resolve(__dirname, `./temp`);
try {
fs.accessSync(tempPath);
} catch (err) {
fs.mkdirSync(tempPath);
}
// todo: 修复路径 1
const { port, attachment } = require('./configs.json');
const body = require('./middlewares/body');
const error = require('./middlewares/error');
const init = require('./middlewares/init');
if (!attachment || attachment.length === 0) {
throw new Error(`未指定文件目录`);
}
const app = new koa();
app.on('error', (err) => {
// console.log(`koa error:`, err);
});
app.use(
koaBody({
multipart: true,
formidable: {
maxFields: 20,
maxFileSize: 1024 * 1024 * 1024 * 1024 * 1024,
uploadDir: tempPath,
hash: 'md5',
keepExtensions: true,
},
}),
);
app.use(error);
app.use(init);
app.use(router.routes());
app.use(body);
const server = http.createServer(app.callback());
server.listen(port, () => {
console.log(`store service is running at ${port}`.green);
});