This commit is contained in:
2026-04-14 11:25:25 +08:00
parent 4cf060136d
commit a0c48937ad
9 changed files with 94 additions and 23 deletions

31
src/server-node.tsx Normal file
View File

@@ -0,0 +1,31 @@
"use server";
import { renderToPipeableStream, renderToString } from 'react-dom/server';
// import A from './pages/a/index.tsx';
import { AEntry } from './browser-entry.tsx';
import AServer from './pages/a/server/index.tsx';
import http from 'http';
const PORT = 3000;
http.createServer((req, res) => {
if (req.url === '/ssr') {
const { pipe } = renderToPipeableStream(<AServer />, {
bootstrapScripts: [],
onShellReady() {
res.writeHead(200, { 'Content-Type': 'text/html' });
pipe(res);
},
onShellError(err) {
console.error('Shell error:', err);
res.writeHead(500);
res.end('Server Error');
}
});
} else {
const str = renderToString(<A />);
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(str);
}
}).listen(PORT, () => {
console.log(`Server running on http://localhost:${PORT}`);
});