Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
Add host option (#588)
Xavier NUNNdcebcb0e73aa
diff --git a/config-sample.ini b/config-sample.iniindex bc88f6e1a3..3292540d88 100644--- a/config-sample.ini+++ b/config-sample.ini@@ -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 portport=8080# true for TLS/SSL/HTTPS (secure), false for HTTP (unsecure).diff --git a/src/services/host.js b/src/services/host.jsnew file mode 100644index 0000000000..e638931bde--- /dev/null+++ b/src/services/host.js@@ -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');diff --git a/src/www b/src/wwwindex d15d679b28..d775fce358 100755--- a/src/www+++ b/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;}-}\ No newline at end of file+}