Add host bind option for frontend (#5014)

* Added IP address bind to HTTP frontend listener

* Changed ip to host in configuration and code

Co-authored-by: romanius <me@romanius.me>
Co-authored-by: Koen Kanters <koenkanters94@gmail.com>
This commit is contained in:
Roman 2020-11-24 00:09:47 +06:00 committed by GitHub
parent 9ee35f6933
commit 481cdefafc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 5 deletions

View File

@ -27,6 +27,7 @@ class Frontend extends Extension {
this.server.on('upgrade', this.onUpgrade);
this.developmentServer = settings.get().frontend.development_server;
this.development = !!this.developmentServer;
this.host = settings.get().frontend.host || '0.0.0.0';
this.port = settings.get().frontend.port || 8080;
this.retainedMessages = new Map();
@ -51,8 +52,8 @@ class Frontend extends Extension {
logger.info(`Running frontend in development mode (${this.developmentServer})`);
}
this.server.listen(this.port);
logger.info(`Started frontend on port ${this.port}`);
this.server.listen(this.port, this.host);
logger.info(`Started frontend on port ${this.host}:${this.port}`);
}
async stop() {

View File

@ -86,7 +86,7 @@ describe('Frontend', () => {
data.writeDefaultState();
settings._reRead();
settings.set(['experimental'], {new_api: true});
settings.set(['frontend'], {port: 8081});
settings.set(['frontend'], {port: 8081, host: "127.0.0.1"});
settings.set(['homeassistant'], true);
zigbeeHerdsman.devices.bulb.linkquality = 10;
});
@ -99,7 +99,7 @@ describe('Frontend', () => {
controller = new Controller();
await controller.start();
expect(mockNodeStatic.variables.path).toBe("my/dummy/path");
expect(mockHTTP.implementation.listen).toHaveBeenCalledWith(8081);
expect(mockHTTP.implementation.listen).toHaveBeenCalledWith(8081, "127.0.0.1");
const mockWSClient = {
implementation: {
@ -197,7 +197,7 @@ describe('Frontend', () => {
controller = new Controller();
await controller.start();
expect(mockHTTPProxy.variables.initParameter).toStrictEqual({ws: true});
expect(mockHTTP.implementation.listen).toHaveBeenCalledWith(8080);
expect(mockHTTP.implementation.listen).toHaveBeenCalledWith(8080, "0.0.0.0");
mockHTTP.variables.onRequest(1, 2);
expect(mockHTTPProxy.implementation.web).toHaveBeenCalledTimes(1);