mirror of
https://github.com/zadam/trilium.git
synced 2025-02-23 22:44:44 +08:00
small fixes / refactoring
This commit is contained in:
parent
4f63284d41
commit
8de67b6945
3 changed files with 11 additions and 7 deletions
|
@ -11,7 +11,8 @@ if (config.https) {
|
|||
const port = require('./src/services/port');
|
||||
const host = require('./src/services/host');
|
||||
|
||||
let options = {timeout: 2000};
|
||||
const options = { timeout: 2000 };
|
||||
|
||||
const callback = res => {
|
||||
console.log(`STATUS: ${res.statusCode}`);
|
||||
if (res.statusCode === 200) {
|
||||
|
@ -20,7 +21,9 @@ const callback = res => {
|
|||
process.exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
let request;
|
||||
|
||||
if (port !== 0) { // TCP socket.
|
||||
const url = `http://${host}:${port}/api/health-check`;
|
||||
request = http.request(url, options, callback);
|
||||
|
@ -29,6 +32,7 @@ if (port !== 0) { // TCP socket.
|
|||
options.path = '/api/health-check';
|
||||
request = http.request(options, callback);
|
||||
}
|
||||
|
||||
request.on("error", err => {
|
||||
console.log("ERROR");
|
||||
process.exit(1);
|
||||
|
|
|
@ -6,8 +6,8 @@ const dataDir = require('./data_dir');
|
|||
function parseAndValidate(portStr, source) {
|
||||
const portNum = parseInt(portStr);
|
||||
|
||||
if (!portNum && portNum !== 0 || portNum < 0 || portNum >= 65536) {
|
||||
console.log(`FATAL ERROR: Invalid port value "${portStr}" from ${source}, should be a number between 0 and 65536.`);
|
||||
if (isNaN(portNum) || portNum < 0 || portNum >= 65536) {
|
||||
console.log(`FATAL ERROR: Invalid port value "${portStr}" from ${source}, should be an integer between 0 and 65536.`);
|
||||
process.exit(-1);
|
||||
}
|
||||
|
||||
|
|
8
src/www
8
src/www
|
@ -100,14 +100,14 @@ async function startTrilium() {
|
|||
*/
|
||||
|
||||
httpServer.keepAliveTimeout = 120000 * 5;
|
||||
const listenTcp = port !== 0;
|
||||
if (listenTcp) {
|
||||
const listenOnTcp = port !== 0;
|
||||
if (listenOnTcp) {
|
||||
httpServer.listen(port, host); // TCP socket.
|
||||
} else {
|
||||
httpServer.listen(host); // Unix socket.
|
||||
}
|
||||
httpServer.on('error', error => {
|
||||
if (!listenTcp || error.syscall !== 'listen') {
|
||||
if (!listenOnTcp || error.syscall !== 'listen') {
|
||||
throw error;
|
||||
}
|
||||
|
||||
|
@ -130,7 +130,7 @@ async function startTrilium() {
|
|||
)
|
||||
|
||||
httpServer.on('listening', () => {
|
||||
if (listenTcp) {
|
||||
if (listenOnTcp) {
|
||||
log.info(`Listening on port ${port}`)
|
||||
} else {
|
||||
log.info(`Listening on unix socket ${host}`)
|
||||
|
|
Loading…
Reference in a new issue