From 43b997b4d783e5f5f57585553949fad07ac58840 Mon Sep 17 00:00:00 2001 From: Ligre Date: Sat, 29 Jul 2023 22:03:44 +0200 Subject: [PATCH] Fix #39 Final changes to support loading a remote JSON config file. Read the documentation to learn how it works: https://github.com/ligreman/king#configuration --- README.md | 34 ++++++++++-- examples/config.json.template | 2 +- src/app/app.component.html | 9 ++-- src/app/app.component.ts | 54 +++++++++++-------- .../dialog-settings.component.html | 8 ++- .../dialog-settings.component.ts | 38 +++++++------ src/app/services/api.service.ts | 2 +- src/app/services/globals.service.ts | 24 ++++++++- src/assets/i18n/en.json | 5 +- src/assets/i18n/es.json | 5 +- 10 files changed, 128 insertions(+), 53 deletions(-) diff --git a/README.md b/README.md index 52f4d1d..40c421c 100644 --- a/README.md +++ b/README.md @@ -54,8 +54,8 @@ application server ([Apache](https://httpd.apache.org/download.cgi), [Nginx](htt King for Kong is an Angular web application without a backend. This is a limitation when you want to have configuration parameters persisted among sessions. To cover part of this feature you can have a JSON config file served by an -application server (apache, nginx... maybe the same that is serving King) as a static file. Then you can set in King -the "Config File Url" parameter to point to that config file, and King will load it on start. +application server (apache, nginx... maybe the same server serving King) as a static file. Then you can set in King +the url to access this configuration file, and King will load it on start. Steps to set this up: @@ -63,11 +63,35 @@ Steps to set this up: 2) Serve it with your web server as an static file. For improved security make sure that only the web server is able to access the file. 3) Open the settings dialog (gear icon on the left of the Kong nodw url field in the header). -4) Set the config file url up. +4) Type the config file url. -Fields allowed in the config file: +Note: If no config url is set, King by default will look for the config file at /config.json. Example: if you are accessing King at http://king.com:8080, King will look for the file at http://king.com:8080/config.json. -* kongNodeUrl: used if you want to set a default kong url node. +Field description of the config file: + +* kongNodeUrl: default kong url node to connect to. + +### King Globals configuration + +Some parameters can be set at code level (they are hardcoded in the source files). You can change them to change King's default behaviour to a certain level. + +The file containing the global configuration is located at `src/app/services/globals.service.ts` + +There you have these variables: + +``` +// Default url for the configuration JSON file +private _CONFIG_URL = '/config.json'; + +// Enable or disable the config dialog in the interface +private _ALLOW_CONFIG = false; + +// Allow users to change the url of the Kong node to connect to +private _ALLOW_CHANGE_KONG_URL = true; + +// Allow users to change the url of the JSON configuration file to load +private _ALLOW_CHANGE_CONFIG_FILE_URL = true; +``` ## Development diff --git a/examples/config.json.template b/examples/config.json.template index 4d85653..7bdb94f 100644 --- a/examples/config.json.template +++ b/examples/config.json.template @@ -1,3 +1,3 @@ { - "kongNodeUrl": "http://patata.com" + "kongNodeUrl": "http://foo-hostname.com" } diff --git a/src/app/app.component.html b/src/app/app.component.html index 4d97fe5..165cd66 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -98,9 +98,10 @@
- @@ -110,6 +111,7 @@ matTooltip="{{'header.menu.kong_node_tooltip' | translate}}" matTooltipClass="tooltip-teal" placeholder="{{'header.menu.kong_node' | translate}}" + [readonly]="!enableKongUrl" type="text"/> @@ -119,7 +121,8 @@
{{ 'header.menu.error_node_field' | translate }}
- {{'header.menu.kong_node_hint' | translate}} + {{'header.menu.kong_node_disabled_hint' | translate}} + {{'header.menu.kong_node_hint' | translate}}