-
-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathentry-server.tsx
More file actions
34 lines (32 loc) · 924 Bytes
/
entry-server.tsx
File metadata and controls
34 lines (32 loc) · 924 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { hasHandler, handleFetch$ } from '@tanstack/bling/server'
import type { APIContext } from 'astro'
import { renderToStringAsync } from 'solid-js/web'
// @ts-ignore
import { manifest } from 'astro:ssr-manifest'
import { manifestContext } from './manifest'
import { routes } from './root'
import { Router, Routes, useRoutes } from '@solidjs/router'
export const requestHandler = async ({ request }: APIContext) => {
if (hasHandler(new URL(request.url).pathname)) {
return await handleFetch$({
request,
})
}
return new Response(
await renderToStringAsync(() => {
const Routes = useRoutes(routes)
return (
<manifestContext.Provider value={manifest}>
<Router url={request.url.toString()}>
<Routes />
</Router>
</manifestContext.Provider>
)
}),
{
headers: {
'content-type': 'text/html',
},
},
)
}