forked from Chinlinlee/raccoon-dicom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
119 lines (92 loc) · 3.06 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
RegExp.prototype.toJSON = RegExp.prototype.toString;
const { raccoonConfig } = require("./config-class");
require('module-alias')(__dirname + "/config/modula-alias/mongodb");
const { app, server } = require("./app");
const bodyParser = require("body-parser");
const session = require("express-session");
const cookieParser = require("cookie-parser");
const compress = require("compression");
const cors = require("cors");
const os = require("os");
let sessionStore = require("connect-mongo");;
let dbInstance = require("mongoose");
let sessionStoreOption = sessionStore.create({
client: dbInstance.connection.getClient(),
dbName: raccoonConfig.dbConfig.dbName
});
const passport = require("passport");
const { DcmQrScp } = require('@dimse');
require("dotenv");
require("./websocket");
app.use(compress());
app.use(cookieParser());
if (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "dev") {
app.use(cors());
}
//#region body parser
app.use(
bodyParser.urlencoded({
extended: true
})
);
app.use(
bodyParser.json({
type: ["application/json", "application/dicom+json"]
})
);
//#endregion
//#region session
app.use(
session({
secret: raccoonConfig.serverConfig.secretKey || "secretKey",
resave: true,
saveUninitialized: false,
cookie: {
httpOnly: true,
maxAge: 60 * 60 * 1000
},
store: sessionStoreOption
})
);
//#endregion
//#region passport
app.use(passport.initialize());
app.use(passport.session());
//#endregion
require("./routes.js")(app);
const PORT = raccoonConfig.serverConfig.port;
server.listen(PORT, () => {
console.log(`http server is listening on port:${PORT}`);
});
let osPlatform = os.platform().toLocaleLowerCase();
if (osPlatform.includes("linux")) {
process.env.OS = "linux";
} else if (osPlatform.includes("win")) {
process.env.OS = "windows";
}
// #region DIMSE
(async () => {
if (raccoonConfig.dicomDimseConfig.enableDimse) {
const { java } = require("./models/DICOM/dcm4che/java-instance");
const net = require("net");
let checkPortServer = net.createServer()
.once("listening", async function () {
checkPortServer.close();
try {
let dcmQrScp = new DcmQrScp();
await dcmQrScp.start();
console.log(`QRSCP Service info: ${raccoonConfig.dicomDimseConfig.aeTitle}@${raccoonConfig.dicomDimseConfig.hostname}:${raccoonConfig.dicomDimseConfig.port}`);
} catch(e) {
if (e.message.includes("Address already in use")) console.log("QRSCP service is already running");
else console.log(e);
}
})
.once("error", function (err) {
if (err.code === "EADDRINUSE") {
console.log("QRSCP's port is already in use, please check is QRSCP running or another app running");
}
})
.listen(raccoonConfig.dicomDimseConfig.port);
}
})();
// #endregion