【发布时间】:2018-01-30 20:46:44
【问题描述】:
是否可以从 firebase 函数插入/更新 html,连接到 firebase 托管的 Create-React-App 的路由,并为 React 页面预渲染 html 的元标记? 在我的实验中:
函数的 index.js:
exports.productPage = functions.https.onRequest((req, res) => {
const html = `<!doctype html>
<head>
<title>Function</title>
</head>
<body>
<h5>FUNCTION</h5>
<div id="root"></div>
</body>
</html>`
res.status(200).send(html);
})
反应路线:
<Route path='/product/:_id' component={ProductPage}/>
firebase.json:
"rewrites": [ {
"source": "/product/**", "function": "productPage"
} ]
如果我转到函数或主机的 url,我会得到标记,仅从函数生成,而不是用函数的新标题对组件做出反应。 这是正确的做法吗?
【问题讨论】:
标签: node.js firebase google-cloud-functions firebase-hosting create-react-app