up
This commit is contained in:
31
src/server-node.tsx
Normal file
31
src/server-node.tsx
Normal 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}`);
|
||||
});
|
||||
Reference in New Issue
Block a user