-
-
Notifications
You must be signed in to change notification settings - Fork 33
fix: 404 when refreshing non-homepage routes #290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Hi @jinrenjie 👋 Sorry for the late reply — too many things piled up, but I finally got a chance to review this handler. Thanks a lot, you did a great job spotting where the issue was and fixing it 👏 I think we should approach this handler a bit differently. Right now, FrontendRequest is designed as the last handler in the chain – it only kicks in when no one else has processed the request. That’s why instead of enumerating all the routes it should serve (like /src/, /assets/, /favicon, etc.), it would be more robust to work from the opposite perspective: We explicitly skip API routes, assets, and other static resources. Everything else should be treated as a frontend route and resolved through the SPA entry point. This way we don’t need to maintain an ever-growing allowlist of frontend pages/URLs. As the application evolves and new pages are added, they’ll just work without changing this handler. Thanks for the contribution! Something like private function isValidRequest(ServerRequestInterface $request): bool
{
$path = $request->getUri()->getPath();
return $path === '/'
|| \str_starts_with($path, '/src/')
|| \str_starts_with($path, '/assets/')
|| $path === '/favicon/favicon.ico'
|| $path === '/bg.jpg'
|| !\str_starts_with($path, '/api'); // <- add this
}and if (
!\str_starts_with($path, '/api')
&& !\str_starts_with($path, '/assets')
&& !\str_contains($path, '/src')
) {
$path = '/index.html';
}
$path = \rtrim($this->publicPath, '/') . '/' . \ltrim($path, '/');Take a look at what I’m suggesting — if you can adjust it this way, that would be awesome. Really appreciate your help on this 🙌 |
butschster
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Take a look at the suggestions I left. If you’d like, you can refine or improve them, and then we’ll be ready to merge. After the merge, I’ll cut a release and we can test it together. Thanks a lot for your help! 🙌
|
@butschster Now I have discovered a new issue. When I refresh the /inspector page, it first enters: server/app/modules/Inspector/Interfaces/Http/Handler/EventHandler.php Lines 63 to 81 in da21392
Causing the request that should have gone to FrontendRequest to be mistakenly recognized as an Inspector Event, which ultimately results in the following error:
|
|
I think we need to fix this line |
@butschster I followed your suggestion and fixed this issue, but I am not sure whether it will have a negative impact on the Inspector SDK. |
|
@jinrenjie Thx a lot! |

What was changed
Fixed an issue where refreshing a page other than the homepage resulted in a 404 error.
Configured the server to correctly handle frontend routes by redirecting them to the index file.
Why?
The application uses client-side routing. Without proper server configuration, refreshing on non-root routes caused the server to look for physical files and return 404.
This fix ensures all routes are handled by the frontend router as intended.
Checklist