import express from 'express'; import React from 'react'; import { renderToString } from 'react-dom/server'; import App from './src/App'; const app = express(); // 静态文件服务 app.use(express.static('public')); // 首页路由 app.get('/', (req, res) => { const initialState = { name: 'John Doe22' }; const html = renderToString(); res.send(` React SSR
${html}
`); }); app.listen(3000, () => { console.log('Server is running at http://localhost:3000'); });