mirror of
https://github.com/zadam/trilium.git
synced 2024-12-26 09:12:08 +08:00
Add host option (#588)
* Added option to configure host * Updated sample config
This commit is contained in:
parent
3d7a5f20e7
commit
dcebcb0e73
3 changed files with 17 additions and 2 deletions
|
@ -3,6 +3,8 @@
|
|||
instanceName=
|
||||
|
||||
[Network]
|
||||
# host setting is relevant only for web deployments - set the host on which the server will listen
|
||||
# host=0.0.0.0
|
||||
# port setting is relevant only for web deployments, desktop builds run on random free port
|
||||
port=8080
|
||||
# true for TLS/SSL/HTTPS (secure), false for HTTP (unsecure).
|
||||
|
|
10
src/services/host.js
Normal file
10
src/services/host.js
Normal file
|
@ -0,0 +1,10 @@
|
|||
const config = require('./config');
|
||||
const env = require('./env');
|
||||
|
||||
let environmentHost;
|
||||
|
||||
if (process.env.TRILIUM_HOST) {
|
||||
environmentHost = process.env.TRILIUM_HOST;
|
||||
}
|
||||
|
||||
module.exports = Promise.resolve(environmentHost || config['Network']['host'] || '0.0.0.0');
|
7
src/www
7
src/www
|
@ -25,6 +25,7 @@ const messagingService = require('./services/messaging');
|
|||
const utils = require('./services/utils');
|
||||
const sqlInit = require('./services/sql_init');
|
||||
const port = require('./services/port');
|
||||
const host = require('./services/host');
|
||||
const semver = require('semver');
|
||||
|
||||
if (!semver.satisfies(process.version, ">=10.5.0")) {
|
||||
|
@ -36,8 +37,10 @@ let httpServer;
|
|||
|
||||
async function startTrilium() {
|
||||
const usedPort = await port;
|
||||
const usedHost = await host;
|
||||
|
||||
app.set('port', usedPort);
|
||||
app.set('host', usedHost);
|
||||
|
||||
if (config['Network']['https']) {
|
||||
if (!config['Network']['keyPath'] || !config['Network']['keyPath'].trim().length) {
|
||||
|
@ -70,7 +73,7 @@ async function startTrilium() {
|
|||
*/
|
||||
|
||||
httpServer.keepAliveTimeout = 120000 * 5;
|
||||
httpServer.listen(usedPort);
|
||||
httpServer.listen(usedPort, usedHost);
|
||||
httpServer.on('error', onError);
|
||||
httpServer.on('listening', () => debug('Listening on port' + httpServer.address().port));
|
||||
|
||||
|
@ -108,4 +111,4 @@ function onError(error) {
|
|||
default:
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue