Skip to content

Commit

Permalink
Merge pull request #116 from Thymis-io/fix/https
Browse files Browse the repository at this point in the history
update controller base URL handling to fix public https usage
  • Loading branch information
elikoga authored Oct 13, 2024
2 parents 9659b42 + d78df70 commit e356e3f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
12 changes: 8 additions & 4 deletions controller/thymis_controller/routers/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ def frontend_binary_path():
return global_settings.FRONTEND_BINARY_PATH


def controller_base_url_host():
return urlparse(global_settings.BASE_URL).netloc
def controller_base_url():
return (
urlparse(global_settings.BASE_URL).scheme
+ "://"
+ urlparse(global_settings.BASE_URL).netloc
)


class Frontend:
Expand Down Expand Up @@ -61,7 +65,7 @@ async def run(self):
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env={
"PUBLIC_CONTROLLER_HOST": controller_base_url_host(),
"PUBLIC_CONTROLLER_HOST": controller_base_url(),
"PATH": os.environ["PATH"],
},
)
Expand All @@ -72,7 +76,7 @@ async def run(self):
env={
"PORT": str(FRONTEND_PORT),
"HOST": "127.0.0.1",
"PUBLIC_CONTROLLER_HOST": controller_base_url_host(),
"PUBLIC_CONTROLLER_HOST": controller_base_url(),
},
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
Expand Down
2 changes: 1 addition & 1 deletion frontend/.env.example
Original file line number Diff line number Diff line change
@@ -1 +1 @@
PUBLIC_CONTROLLER_HOST=127.0.0.1:8000
PUBLIC_CONTROLLER_HOST=http://127.0.0.1:8000
5 changes: 2 additions & 3 deletions frontend/src/hooks.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ export const handleFetch: HandleFetch = async ({ request, fetch, event }) => {
const cookies = request.headers.get('cookie') || '';
request.headers.set('cookie', `${cookies}; session=${session}`);
}
// replace host with controllerHost
let new_url = request.url.replace(event.url.host, controllerHost);
new_url = new_url.replace('https:', 'http:');
const parsedControllerHost = new URL(controllerHost);
let new_url = request.url.replace(parsedRequestUrl.origin, parsedControllerHost.origin);
console.log('fetching:', new_url);
request = new Request(new_url, request);
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { env } from '$env/dynamic/public';

export let controllerHost = env.PUBLIC_CONTROLLER_HOST
? env.PUBLIC_CONTROLLER_HOST
: '127.0.0.1:8000'; // default
: 'http://127.0.0.1:8000'; // default
if (browser) {
// set controllerHost to the current host/api
controllerHost = window.location.host;
Expand Down

0 comments on commit e356e3f

Please sign in to comment.