Repository navigation
Description
Describe the bug
When the panel is enabled --enable-panel, the logic that handles the panel endpoints will only serve /index.html and any assets that are discovered under client/dist when building.
The logic that handles this is at:
wasm-workers-server/crates/panel/src/handlers/panel.rs
Lines 18 to 29 in 549387b
| let path = if path.len() == 0 { | |
| "index.html" | |
| } else { | |
| path.as_str().strip_prefix('/').unwrap() | |
| }; | |
| match Asset::get(path) { | |
| Some(content) => HttpResponse::Ok() | |
| .content_type(from_path(path).first_or_octet_stream().as_ref()) | |
| .body(content.data.into_owned()), | |
| None => HttpResponse::NotFound().body("404 Not Found"), | |
| } |
There are other virtual paths such as /_panel/workers that are not covered by any of this cases.
Ideally, to avoid duplicating routing in multiple places, this logic should:
- If path is empty, default to
index.html, as per the current logic. - If an asset exists, serve it, as per the current logic.
- Otherwise, serve a static page, that will perform an AJAX request to the current path and will forward the response to the client.
This way, we keep the current Single Page Application (SPA) approach, while making arbitrary paths directly visitable (e.g. reload endpoint, write path in location bar and hit enter...)
Reproduction steps
Run wws with --enable-panel. Visit /_panel/workers. The server will return a 404 HTTP status code.
Expected behavior
Visiting /_panel/workers directly should be equivalent to visiting / and navigating through the UI to the list of workers.
Additional context
No response
Activity
dierbei commentedon Aug 9, 2023
I reproduced the problem, except I don't know what it is now.
But it looks like the odds are that the front-end file isn't receiving the route forwarding.
Because I tried to change the path to
/_panel/workersand I can't access it either.It only works if you visit
/panelfirst, go to theUIand then click on the sidebar.dierbei commentedon Aug 10, 2023
I tried to fix this bug and was able to access
/_panel/workersthrough my browser.I mainly utilized the fact that the pages I couldn't find were using the front end to forward requests.
I'm not sure if this is the desired result, can you help me out?
panel forward
fix: return the panel index.html file by default (#193)
Angelmmiguel commentedon Aug 10, 2023
Hello @dierbei,
Thank you for taking the issue and submit the PR to fix it! 👏
Yes, this is the expected result. The administration panel is a Single Page Application (SPA), so the routing happens in the browser. If you access the panel on
/and then navigate to/workersthrough a link, it works. However, if you reload the site, it will return a 404 error as the admin paneldistpackage doesn't include anyworkers.htmlfile.The solution you proposed fix this error by returning the
index.htmlfile when there's no file in the admin paneldistfolder that matches it.This is the reason why you were getting these errors. The server didn't find any
workers.htmlfile.Thank you!!