Closed 1089109 closed 1 month ago
content-length: 37764
"umi": "3.4.25"
http://www.huangcy.com/course/chapter/detail?chapterId=151&courseId=82
http://www.huangcy.com/course/chapter/detail?chapterId=150&courseId=82
现在控制台只输出5555 web
const CourseDetail = (props: CourseDetailProps) => { return
CourseDetail.getInitialProps = (async ({ isServer, store, history }) => { if (!isServer) return; console.log(11111, 'web') ...... console.log(5555, 'web') const { data: currentChapter } = await getChapterDetail({ id: Number(chapterId), isServer }).catch(err => { console.log('errror ?', err ) }); console.log(4444, 'web') let detailData: Course.CourseRule | null = null if (success && data) { detailData = data; } let content = ''; // 章节内容 let headerLinks = ''; // 将li 改成a链接
console.log(1) console.log(currentChapter, 'currentChapter') console.log(2) // 右侧的索引目录修改 if (currentChapter) { content = currentChapter.content; content = setContentHeader(currentChapter.content, currentChapter.headerContent); headerLinks = setHeaderLink(currentChapter.headerContent); } console.log(3) // 右侧的最多浏览文章/最多评论文章... const { data: newInfo } = await getMaxArticle({ current: 1, pageSize: 20, isBrowse: true, isNewArticle: true, isComment: true, isServer, }); const { newArticleList = [], browseList = [], commentList = [], } = newInfo as Classify.ArticleMaxRule; return Promise.resolve({ detailData, global, currentChapter, content, headerLinks, chapterId, newArticleList, browseList, commentList, })
}) as IGetInitialProps;
`const Koa = require('koa'); const compress = require('koa-compress'); const mount = require('koa-mount'); const { join, extname } = require('path'); const { parseCookie, parseNavLang } = require('./serverHelper'); const port = 8020; // 端口 const root = join(__dirname, 'dist');
const app = new Koa(); app.use( compress({ threshold: 1024, gzip: { flush: require('zlib').constants.Z_SYNC_FLUSH, }, deflate: { flush: require('zlib').constants.Z_SYNC_FLUSH, }, br: false, // 禁用br解决https gzip不生效加载缓慢问题 }), );
let render; app.use(async (ctx, next) => { /**
同时获取浏览器的默认语言,处理好 */ global._cookies = parseCookie(ctx); global._navigatorLang = parseNavLang(ctx);
const ext = extname(ctx.request.path);
// 符合要求的路由才进行服务端渲染,否则走静态文件逻辑 if (!ext || ext === '.html') { if (!render) { render = require('./dist/umi.server'); } // 这里默认是字符串渲染 ctx.type = 'text/html'; ctx.status = 200; const { html, error } = await render({ path: ctx.request.url, mode: 'stream', }); if (error) { console.log('----------------服务端报错-------------------', error); } ctx.body = html; } else { await next(); } });
app.use(mount('/dist', require('koa-static')(root)));
app.listen(port, () => { console.log(SSR服务启动成功 http://localhost:${port} 真实接口在80上,由于csr需要代理api接口); });
SSR服务启动成功 http://localhost:${port} 真实接口在80上,由于csr需要代理api接口
module.exports = app.callback(); `
由于缺乏足够的信息,我们暂时关闭了该 Issue。请修改(不要回复) Issue 提供最小重现以重新开启。谢谢。
接口内容返回有37764,已经渲染失败了
content-length: 37764
umi版本
"umi": "3.4.25"
现在测试到的是,其它页面是正常打开的,只有内容过多时才会失败
渲染失败的地址
http://www.huangcy.com/course/chapter/detail?chapterId=151&courseId=82
成功的地址
http://www.huangcy.com/course/chapter/detail?chapterId=150&courseId=82
页面请求接口的地方
const CourseDetail = (props: CourseDetailProps) => { return
CourseDetail.getInitialProps = (async ({ isServer, store, history }) => { if (!isServer) return; console.log(11111, 'web') ...... console.log(5555, 'web') const { data: currentChapter } = await getChapterDetail({ id: Number(chapterId), isServer }).catch(err => { console.log('errror ?', err ) }); console.log(4444, 'web') let detailData: Course.CourseRule | null = null if (success && data) { detailData = data; } let content = ''; // 章节内容 let headerLinks = ''; // 将li 改成a链接
}) as IGetInitialProps;
server.js
`const Koa = require('koa'); const compress = require('koa-compress'); const mount = require('koa-mount'); const { join, extname } = require('path'); const { parseCookie, parseNavLang } = require('./serverHelper'); const port = 8020; // 端口 const root = join(__dirname, 'dist');
const app = new Koa(); app.use( compress({ threshold: 1024, gzip: { flush: require('zlib').constants.Z_SYNC_FLUSH, }, deflate: { flush: require('zlib').constants.Z_SYNC_FLUSH, }, br: false, // 禁用br解决https gzip不生效加载缓慢问题 }), );
let render; app.use(async (ctx, next) => { /**
同时获取浏览器的默认语言,处理好 */ global._cookies = parseCookie(ctx); global._navigatorLang = parseNavLang(ctx);
const ext = extname(ctx.request.path);
// 符合要求的路由才进行服务端渲染,否则走静态文件逻辑 if (!ext || ext === '.html') { if (!render) { render = require('./dist/umi.server'); } // 这里默认是字符串渲染 ctx.type = 'text/html'; ctx.status = 200; const { html, error } = await render({ path: ctx.request.url, mode: 'stream', }); if (error) { console.log('----------------服务端报错-------------------', error); } ctx.body = html; } else { await next(); } });
app.use(mount('/dist', require('koa-static')(root)));
app.listen(port, () => { console.log(
SSR服务启动成功 http://localhost:${port} 真实接口在80上,由于csr需要代理api接口
); });module.exports = app.callback(); `