Introduce ESLint and Prettier
This commit is contained in:
1 parent
9c943d0bbf
commit
e494bdca8a
26 files changed
+1585
-1594
No files matched your search
+25
-26
@@ -20,8 +20,7 @@
|
||||
|
||||
const service = process.argv[2];
|
||||
|
||||
if (service == null)
|
||||
throw new Error("Missing argument cwmp, fs, or nbi");
|
||||
if (service == null) throw new Error("Missing argument cwmp, fs, or nbi");
|
||||
|
||||
const cluster = require("cluster");
|
||||
const path = require("path");
|
||||
@@ -39,17 +38,15 @@ const networkInterface = config.get(`${service.toUpperCase()}_INTERFACE`);
|
||||
const port = config.get(`${service.toUpperCase()}_PORT`);
|
||||
const useHttps = config.get(`${service.toUpperCase()}_SSL`);
|
||||
|
||||
const {listener, onConnection} = require(`./${service}`);
|
||||
const { listener, onConnection } = require(`./${service}`);
|
||||
|
||||
let server;
|
||||
|
||||
function closeServer(timeout, callback) {
|
||||
if (!server)
|
||||
return callback();
|
||||
if (!server) return callback();
|
||||
|
||||
setTimeout(() => {
|
||||
if (!callback)
|
||||
return;
|
||||
if (!callback) return;
|
||||
|
||||
// Ignore HTTP requests from connection that may still be open
|
||||
server.removeListener("request", listener);
|
||||
@@ -60,9 +57,8 @@ function closeServer(timeout, callback) {
|
||||
setTimeout(cb, 1000);
|
||||
}, timeout).unref();
|
||||
|
||||
server.close(function() {
|
||||
if (!callback)
|
||||
return;
|
||||
server.close(() => {
|
||||
if (!callback) return;
|
||||
|
||||
let cb = callback;
|
||||
callback = null;
|
||||
@@ -81,12 +77,11 @@ function exit() {
|
||||
db.disconnect();
|
||||
cache.disconnect();
|
||||
extensions.killAll();
|
||||
if (cluster.worker)
|
||||
cluster.worker.disconnect();
|
||||
if (cluster.worker) cluster.worker.disconnect();
|
||||
});
|
||||
}
|
||||
|
||||
process.on("uncaughtException", (err) => {
|
||||
process.on("uncaughtException", err => {
|
||||
logger.error({
|
||||
message: "Uncaught exception",
|
||||
exception: err,
|
||||
@@ -98,7 +93,10 @@ process.on("uncaughtException", (err) => {
|
||||
if (useHttps) {
|
||||
const httpsKey = path.resolve(config.get("CONFIG_DIR"), `${service}.key`);
|
||||
const httpsCert = path.resolve(config.get("CONFIG_DIR"), `${service}.crt`);
|
||||
const httpsCa = path.resolve(config.get("CONFIG_DIR"), `${service}.ca-bundle`);
|
||||
const httpsCa = path.resolve(
|
||||
config.get("CONFIG_DIR"),
|
||||
`${service}.ca-bundle`
|
||||
);
|
||||
const options = {
|
||||
key: fs.readFileSync(httpsKey),
|
||||
cert: fs.readFileSync(httpsCert)
|
||||
@@ -106,24 +104,25 @@ if (useHttps) {
|
||||
|
||||
try {
|
||||
// Use intermediate certificates if available
|
||||
options.ca = fs.readFileSync(httpsCa).toString().match(/\-+BEGIN CERTIFICATE\-+[0-9a-zA-Z\+\-\/\=\s]+?\-+END CERTIFICATE\-+/g);
|
||||
} catch (error) {}
|
||||
options.ca = fs
|
||||
.readFileSync(httpsCa)
|
||||
.toString()
|
||||
.match(/-+BEGIN CERTIFICATE-+[0-9a-zA-Z+\-/=\s]+?-+END CERTIFICATE-+/g);
|
||||
} catch (error) {
|
||||
// No intermediate certificate
|
||||
}
|
||||
server = https.createServer(options, listener);
|
||||
if (onConnection != null)
|
||||
server.on("secureConnection", onConnection);
|
||||
if (onConnection != null) server.on("secureConnection", onConnection);
|
||||
} else {
|
||||
server = http.createServer(listener);
|
||||
if (onConnection != null)
|
||||
server.on("connection", onConnection);
|
||||
if (onConnection != null) server.on("connection", onConnection);
|
||||
}
|
||||
|
||||
db.connect((err) => {
|
||||
if (err)
|
||||
throw err;
|
||||
db.connect(err => {
|
||||
if (err) throw err;
|
||||
|
||||
cache.connect(function(err) {
|
||||
if (err)
|
||||
throw err;
|
||||
cache.connect(err => {
|
||||
if (err) throw err;
|
||||
|
||||
server.listen(port, networkInterface);
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user