Фикс 404 при обновелнии страницы

This commit is contained in:
2026-07-31 06:30:45 -07:00
parent 7af3c46bfe
commit aea0b94598
3 changed files with 58 additions and 36 deletions

View File

@@ -1,5 +1,5 @@
import { copyFile, mkdir } from 'node:fs/promises';
import { resolve } from 'node:path';
import { dirname, resolve } from 'node:path';
const root = process.cwd();
const outputDirectory = resolve(root, 'dist');
@@ -20,13 +20,17 @@ await copyFile(
resolve(serverDirectory, 'index.js'),
);
// Emit an extensionless HTML match for every client-side route. This keeps
// browser refreshes working even when the asset layer handles navigations
// before the Worker gets a chance to return the SPA fallback.
// Emit both clean-URL and directory-index shells for every client-side route.
// The directory copy also supports basic Nginx static configurations that do
// not rewrite missing paths to the root application shell.
await Promise.all(
browserRoutes.map(async (route) => {
const routeFile = resolve(outputDirectory, `${route}.html`);
await mkdir(resolve(routeFile, '..'), { recursive: true });
const routeDirectory = resolve(outputDirectory, route);
await mkdir(dirname(routeFile), { recursive: true });
await mkdir(routeDirectory, { recursive: true });
await copyFile(appShell, routeFile);
await copyFile(appShell, resolve(routeDirectory, 'index.html'));
}),
);