Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/01_template/public/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Not Found 404</h1>
7 changes: 3 additions & 4 deletions packages/waku/src/lib/vite-entries/entry.server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { flags, config, isBuild } from 'virtual:vite-rsc-waku/config';
import { compress } from 'hono/compress';
import { serveStatic } from '@hono/node-server/serve-static';
import path from 'node:path';
import fs from 'node:fs';
import { DIST_PUBLIC } from '../constants.js';
import { INTERNAL_setAllEnv } from '../../server.js';
import notFountHtml from 'virtual:vite-rsc-waku/404';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

notFountHtml typo. It should be notFoundHtml.


function createApp(app: Hono) {
INTERNAL_setAllEnv(process.env as any);
Expand All @@ -31,9 +31,8 @@ function createApp(app: Hono) {
}
app.use(createHonoHandler());
app.notFound((c) => {
const file = path.join(config.distDir, DIST_PUBLIC, '404.html');
if (fs.existsSync(file)) {
return c.html(fs.readFileSync(file, 'utf8'), 404);
if (notFountHtml) {
return c.html(notFountHtml, 404);
}
return c.text('404 Not Found', 404);
});
Expand Down
7 changes: 7 additions & 0 deletions packages/waku/src/lib/vite-rsc/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,13 @@ if (import.meta.hot) {
export const isBuild = ${JSON.stringify(this.environment.mode === 'build')};
`;
}),
createVirtualPlugin('vite-rsc-waku/404', async function () {
const notFoundHtmlPath = path.resolve(DIST_PUBLIC, '404.html');
if (!fs.existsSync(notFoundHtmlPath)) {
return `export default undefined`;
}
return `export { default } from ${JSON.stringify(notFoundHtmlPath + "?raw")}`;
}),
{
// rewrite `react-server-dom-webpack` in `waku/minimal/client`
name: 'rsc:waku:patch-webpack',
Expand Down
5 changes: 5 additions & 0 deletions packages/waku/src/lib/vite-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@ declare module 'virtual:vite-rsc-waku/fallback-html' {
const default_: string;
export default default_;
}

declare module 'virtual:vite-rsc-waku/404' {
const default_: string;
export default default_;
}
Loading