-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathserver.js
75 lines (57 loc) · 1.59 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const bodyParser = require('body-parser')
const express = require('express')
const CORS = require("cors")
const fileUpload = require('express-fileupload');
const mongoose = require('mongoose');
const fs = require('fs')
const fse = require('fs-extra')
const path = require("path")
const config = require('./config')
if(!fs.existsSync(config.service.modelDir)){
fse.mkdirs(config.service.modelDir)
}
if(!fs.existsSync(config.service.tempDir)){
fse.mkdirs(config.service.tempDir)
}
if(!fs.existsSync(config.service.workDir)){
fse.mkdirs(config.service.workDir)
}
mongoose.connect(config.service.db.mongo.url, {
useNewUrlParser: true,
useUnifiedTopology: true
})
const app = express();
app.use(CORS({
origin: '*'
}))
app.use(fileUpload({
useTempFiles: true,
tempFileDir: config.service.modelDir,
limits: {
fileSize: 1024 * 1024 * 1024
}
}));
app.use(bodyParser.text());
app.use(bodyParser.urlencoded({
parameterLimit: 100000,
limit: '50mb',
extended: true
}));
app.use(bodyParser.json({
limit: '50mb'
}));
routes = [
require("./src/javascript/service"),
require("./src/javascript/exists_model")
]
.concat(require("./src/javascript/model"))
app.get("/", (req,res) => {
res.send({service: "JACE-ITA"})
})
routes.forEach( route => {
app[route.method](route.path, route.handler)
})
app.use(express.static(config.service.modelDir))
app.listen(config.service.port, () => {
console.log(`!!!JACE-ITA SERVICE for starts on port ${config.service.port} in ${config.service.mode} mode.`);
});