Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: reads GUI base path from DOM (#474)
Adds a `<base>` tag to the index.html file which will be set to an actual base path during development and the GO template placeholder `{{.BaseGuiPath}}` for production. Upon serving the GUI application, the placeholder will be replaced with the actual GUI base path. Adds the `kuma-config` script tag containing `{{.}}` to the index.html file which will be replaced via Go templating with a basic data structure that, among other things, will hold the actual API base URL and the GUI base path. Reads the API base URL and the GUI base path from the index.html file replacing any attempt of determining it from the current URL which is error-prone and inflexible. Signed-off-by: Philipp Rudloff <philipp.rudloff@konghq.com>
- Loading branch information
1 parent
2d46751
commit 6d56199
Showing
28 changed files
with
426 additions
and
232 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,28 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width,initial-scale=1" /> | ||
|
||
<link rel="icon" href="/favicon.png" /> | ||
<title>Manager</title> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width,initial-scale=1" /> | ||
<!-- This trailing slash matters! Do not remove it. See also: https://stackoverflow.com/a/26043021/2036825 --> | ||
<base href="<%- baseGuiPath %>/" /> | ||
|
||
<script type="module" src="/src/main.ts"></script> | ||
</head> | ||
<body> | ||
<noscript> | ||
<strong> | ||
We're sorry but this site doesn't work properly without JavaScript enabled. Please enable it to continue. | ||
</strong> | ||
</noscript> | ||
<link rel="icon" href="/favicon.png" /> | ||
<title>Manager</title> | ||
|
||
<script type="application/json" id="kuma-config"><%- config %></script> | ||
|
||
<script type="module" src="/src/main.ts"></script> | ||
</head> | ||
|
||
<body> | ||
<noscript> | ||
<strong> | ||
We're sorry but this site doesn't work properly without JavaScript enabled. Please enable it to continue. | ||
</strong> | ||
</noscript> | ||
|
||
<div id="app"></div> | ||
</body> | ||
|
||
<div id="app"></div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Only used for Netlify deployment previews. | ||
# Redirects all requests back to index.html to make vue router’s history mode work in Netlify environments (see https://router.vuejs.org/guide/essentials/history-mode.html#html5-mode). | ||
|
||
/* /index.html 200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { describe, expect, test } from '@jest/globals' | ||
|
||
import { RestClient } from './RestClient' | ||
|
||
describe('RestClient', () => { | ||
test('has expected initial base URL', () => { | ||
const restClient = new RestClient() | ||
|
||
expect(restClient.baseUrl).toBe('http://localhost:5681') | ||
}) | ||
|
||
test.each([ | ||
['api', 'http://localhost:5681/api'], | ||
['/api', 'http://localhost:5681/api'], | ||
['/api/', 'http://localhost:5681/api'], | ||
['test/api', 'http://localhost:5681/test/api'], | ||
['/test/api', 'http://localhost:5681/test/api'], | ||
['/test/api/', 'http://localhost:5681/test/api'], | ||
['http://localhost:1234/api', 'http://localhost:1234/api'], | ||
['http://localhost:1234/api/', 'http://localhost:1234/api'], | ||
])('sets expected base URL for “%s”', (newBaseUrl, expectedBaseUrl) => { | ||
const restClient = new RestClient() | ||
|
||
restClient.baseUrl = newBaseUrl | ||
|
||
expect(restClient.baseUrl).toBe(expectedBaseUrl) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.