Skip to content

Commit 9630949

Browse files
authored
Merge pull request #290 from jinrenjie/master
fix: 404 when refreshing non-homepage routes
2 parents 6c401a3 + 72c6141 commit 9630949

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

app/modules/Inspector/Interfaces/Http/Handler/EventHandler.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ private function listenEvent(ServerRequestInterface $request): ?EventType
7272
if (
7373
$request->hasHeader('X-Inspector-Key')
7474
|| $request->hasHeader('X-Inspector-Version')
75-
|| \str_ends_with((string) $request->getUri(), 'inspector')
75+
|| (
76+
!\str_starts_with($request->getUri()->getPath(), '/inspector')
77+
&& \str_ends_with((string) $request->getUri(), 'inspector')
78+
)
7679
) {
7780
return new EventType(type: 'inspector');
7881
}

app/src/Interfaces/Http/Handler/FrontendRequest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ public function handle(ServerRequestInterface $request, \Closure $next): Respons
3636

3737
if ($path === '/') {
3838
$path = '/index.html';
39+
} elseif (
40+
!\str_starts_with($path, '/api')
41+
&& !\str_starts_with($path, '/assets')
42+
&& !\str_contains($path, '/src')
43+
) {
44+
$path = '/index.html';
3945
}
4046

4147
$path = $this->publicPath . $path;
@@ -71,6 +77,7 @@ private function isValidRequest(ServerRequestInterface $request): bool
7177
|| \str_starts_with($path, '/src/')
7278
|| \str_starts_with($path, '/assets/')
7379
|| $path === '/favicon/favicon.ico'
74-
|| $path === '/bg.jpg';
80+
|| $path === '/bg.jpg'
81+
|| !\str_starts_with($path, '/api');
7582
}
7683
}

0 commit comments

Comments
 (0)