Skip to content

Commit 1e834bf

Browse files
committed
feat: enhance SSR route handling with DOM manipulation
- Integrated DOMParser from linkedom to parse the HTML document. - Injected configuration into the document using the new injectConfigToDocument function. - Updated the response to return the modified HTML for improved server-side rendering. Signed-off-by: Innei <tukon479@gmail.com>
1 parent 124f6ae commit 1e834bf

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

apps/ssr/src/app/route.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1+
import { DOMParser } from 'linkedom'
12
import type { NextRequest } from 'next/server'
23

3-
import indexHtml from '../index.html'
4+
import { injectConfigToDocument } from '~/lib/injectable'
45

56
export const GET = async (req: NextRequest) => {
67
if (process.env.NODE_ENV === 'development') {
78
return import('./[...all]/dev').then((m) => m.handler(req))
89
}
910

10-
return new Response(indexHtml, {
11+
const indexHtml = await import('../index.html').then((m) => m.default)
12+
13+
const document = new DOMParser().parseFromString(indexHtml, 'text/html')
14+
injectConfigToDocument(document)
15+
return new Response(document.documentElement.outerHTML, {
1116
headers: {
1217
'Content-Type': 'text/html',
1318
'X-SSR': '1',

0 commit comments

Comments
 (0)