diff --git a/lib/extension/frontend.ts b/lib/extension/frontend.ts index 4dc324fb06..aa1d50423d 100644 --- a/lib/extension/frontend.ts +++ b/lib/extension/frontend.ts @@ -74,7 +74,10 @@ export default class Frontend extends Extension { this.wss = new WebSocket.Server({noServer: true}); this.wss.on('connection', this.onWebSocketConnection); - if (this.host.startsWith('/')) { + if (!this.host) { + this.server.listen(this.port); + logger.info(`Started frontend on port ${this.port}`); + } else if (this.host.startsWith('/')) { this.server.listen(this.host); logger.info(`Started frontend on socket ${this.host}`); } else { diff --git a/lib/util/settings.schema.json b/lib/util/settings.schema.json index e1cb739141..35a85b6cc5 100644 --- a/lib/util/settings.schema.json +++ b/lib/util/settings.schema.json @@ -371,11 +371,10 @@ "requiresRestart": true }, "host": { - "type": "string", + "type": ["string", "null"], "title": "Bind host", "description": "Frontend binding host. Binds to a unix socket when an absolute path is given instead.", - "examples": ["127.0.0.1", "/run/zigbee2mqtt/zigbee2mqtt.sock"], - "default": "0.0.0.0", + "examples": ["127.0.0.1", "::1", "/run/zigbee2mqtt/zigbee2mqtt.sock"], "requiresRestart": true }, "auth_token": { diff --git a/lib/util/settings.ts b/lib/util/settings.ts index 162bca8022..bb5c6cb430 100644 --- a/lib/util/settings.ts +++ b/lib/util/settings.ts @@ -150,7 +150,7 @@ function loadSettingsWithDefaults(): void { } if (_settingsWithDefaults.frontend) { - const defaults = {port: 8080, auth_token: false, host: '0.0.0.0'}; + const defaults = {port: 8080, auth_token: false}; const s = typeof _settingsWithDefaults.frontend === 'object' ? _settingsWithDefaults.frontend : {}; // @ts-ignore _settingsWithDefaults.frontend = {}; diff --git a/test/frontend.test.js b/test/frontend.test.js index b164123c75..7a0ab1ff14 100644 --- a/test/frontend.test.js +++ b/test/frontend.test.js @@ -135,6 +135,30 @@ describe('Frontend', () => { mockHTTPS.implementation.listen.mockClear(); }); + it('Start/stop without host', async () => { + settings.set(['frontend'], {port: 8081}); + controller = new Controller(jest.fn(), jest.fn()); + await controller.start(); + expect(mockNodeStatic.variables.path).toBe("my/dummy/path"); + expect(mockHTTP.implementation.listen).toHaveBeenCalledWith(8081); + const mockWSClient = { + implementation: { + terminate: jest.fn(), + send: jest.fn(), + }, + events: {}, + }; + mockWS.implementation.clients.push(mockWSClient.implementation); + await controller.stop(); + expect(mockWSClient.implementation.terminate).toHaveBeenCalledTimes(1); + expect(mockHTTP.implementation.close).toHaveBeenCalledTimes(1); + expect(mockWS.implementation.close).toHaveBeenCalledTimes(1); + mockWS.implementation.close.mockClear(); + mockHTTP.implementation.close.mockClear(); + mockHTTP.implementation.listen.mockClear(); + mockHTTPS.implementation.listen.mockClear(); + }); + it('Start/stop unix socket', async () => { settings.set(['frontend'], {host: "/tmp/zigbee2mqtt.sock"}); controller = new Controller(jest.fn(), jest.fn()); diff --git a/test/settings.test.js b/test/settings.test.js index 8171799a70..d7f658720e 100644 --- a/test/settings.test.js +++ b/test/settings.test.js @@ -935,7 +935,7 @@ describe('Settings', () => { }); settings.reRead(); - expect(settings.get().frontend).toStrictEqual({port: 8080, auth_token: false, host: '0.0.0.0'}) + expect(settings.get().frontend).toStrictEqual({port: 8080, auth_token: false}) }); it('Baudrate config', () => {