Skip to content

Commit 766aeba

Browse files
Update README and small fix for error handling in server
1 parent 9dd4a3f commit 766aeba

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Vite + Solid ~ Rollup + Fastify
22

3-
A simple example to develop front-end app with Vite and SolidJS, as well as Fastify back-end support through Vite's [`server.proxy`](https://vite.dev/config/server-options#server-proxy) [config](./vite.config.ts#L12) and bundled with Rollup.
3+
A simple example to develop front-end app with Vite and SolidJS, as well as Fastify back-end support through Vite's [`server.proxy`](https://vite.dev/config/server-options#server-proxy) [config](./vite.config.ts#L15) and bundled with Rollup.
44

55
## Usage
66

@@ -35,7 +35,7 @@ npm run build:server
3535

3636
You can now serve the production build with `npm run preview`. Or just run `node .` at [`dist`](./dist/index.js) folder, it's generally fully portable and minified by `esbuild`. You can adjust the build output by editing the [`vite.config.ts`](./vite.config.ts) file for front-end and [`rollup.config.ts`](./rollup.config.ts) for back-end.
3737

38-
The API endpoint also works alongside [Solid Router](https://docs.solidjs.com/solid-router), including 404 and 500 error pages. Check out [`src/client/index.tsx`](./src/client/index.tsx#L23) and see how the Fastify server handles SPA requests in [`src/server/index.ts`](./src/server/index.ts#L33).
38+
The API endpoint also works alongside [Solid Router](https://docs.solidjs.com/solid-router), including 404 and 500 error pages. Check out [`src/client/index.tsx`](./src/client/index.tsx#L23) and see how the Fastify server handles SPA requests in [`src/server/index.ts`](./src/server/index.ts#L34).
3939

4040
### Learn more on the [Solid Website](https://solidjs.com) and come chat with us on our [Discord](https://discord.com/invite/solidjs)
4141

src/server/index.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,16 @@ app.setNotFoundHandler((request, reply) => {
3939
}
4040
})
4141

42-
app.setErrorHandler((error, _, reply) => {
43-
reply
44-
.status(error?.statusCode || 500)
45-
.header('Content-Type', 'text/html')
46-
.send(fallback)
42+
app.setErrorHandler((error, request, reply) => {
43+
if (probablyBrowser(request.headers)) {
44+
reply
45+
.status(error?.statusCode || 500)
46+
.header('Content-Type', 'text/html')
47+
.send(fallback)
48+
} else {
49+
reply.status(error?.statusCode || 500).send('Server fault')
50+
console.error(error)
51+
}
4752
})
4853

4954
// Not must be `/api`, don't forget to update `vite.config.ts`'s `server.proxy`

0 commit comments

Comments
 (0)