mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 05:28:59 +01:00 
			
		
		
		
	Merge pull request #3699 from new-sashok724/unix-sockets
Support listening on the unix socket
This commit is contained in:
		
						commit
						4f63284d41
					
				@ -10,16 +10,25 @@ if (config.https) {
 | 
			
		||||
 | 
			
		||||
const port = require('./src/services/port');
 | 
			
		||||
const host = require('./src/services/host');
 | 
			
		||||
const url = `http://${host}:${port}/api/health-check`;
 | 
			
		||||
const options = { timeout: 2000 };
 | 
			
		||||
const request = http.request(url, options, res => {
 | 
			
		||||
 | 
			
		||||
let options = {timeout: 2000};
 | 
			
		||||
const callback = res => {
 | 
			
		||||
    console.log(`STATUS: ${res.statusCode}`);
 | 
			
		||||
    if (res.statusCode === 200) {
 | 
			
		||||
        process.exit(0);
 | 
			
		||||
    } else {
 | 
			
		||||
        process.exit(1);
 | 
			
		||||
    }
 | 
			
		||||
});
 | 
			
		||||
};
 | 
			
		||||
let request;
 | 
			
		||||
if (port !== 0) { // TCP socket.
 | 
			
		||||
    const url = `http://${host}:${port}/api/health-check`;
 | 
			
		||||
    request = http.request(url, options, callback);
 | 
			
		||||
} else { // Unix socket.
 | 
			
		||||
    options.socketPath = host;
 | 
			
		||||
    options.path = '/api/health-check';
 | 
			
		||||
    request = http.request(options, callback);
 | 
			
		||||
}
 | 
			
		||||
request.on("error", err => {
 | 
			
		||||
    console.log("ERROR");
 | 
			
		||||
    process.exit(1);
 | 
			
		||||
 | 
			
		||||
@ -6,7 +6,7 @@ const dataDir = require('./data_dir');
 | 
			
		||||
function parseAndValidate(portStr, source) {
 | 
			
		||||
    const portNum = parseInt(portStr);
 | 
			
		||||
 | 
			
		||||
    if (!portNum || portNum < 0 || portNum >= 65536) {
 | 
			
		||||
    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.`);
 | 
			
		||||
        process.exit(-1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										17
									
								
								src/www
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								src/www
									
									
									
									
									
								
							@ -100,9 +100,14 @@ async function startTrilium() {
 | 
			
		||||
     */
 | 
			
		||||
 | 
			
		||||
    httpServer.keepAliveTimeout = 120000 * 5;
 | 
			
		||||
    httpServer.listen(port, host);
 | 
			
		||||
    const listenTcp = port !== 0;
 | 
			
		||||
    if (listenTcp) {
 | 
			
		||||
      httpServer.listen(port, host); // TCP socket.
 | 
			
		||||
    } else {
 | 
			
		||||
      httpServer.listen(host); // Unix socket.
 | 
			
		||||
    }
 | 
			
		||||
    httpServer.on('error', error => {
 | 
			
		||||
            if (error.syscall !== 'listen') {
 | 
			
		||||
            if (!listenTcp || error.syscall !== 'listen') {
 | 
			
		||||
                throw error;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
@ -124,7 +129,13 @@ async function startTrilium() {
 | 
			
		||||
        }
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    httpServer.on('listening', () => log.info(`Listening on port ${httpServer.address().port}`));
 | 
			
		||||
    httpServer.on('listening', () => {
 | 
			
		||||
        if (listenTcp) {
 | 
			
		||||
            log.info(`Listening on port ${port}`)
 | 
			
		||||
        } else {
 | 
			
		||||
            log.info(`Listening on unix socket ${host}`)
 | 
			
		||||
        }
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    ws.init(httpServer, sessionParser);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user