正在调整服务器端渲染和谷歌云功能。在托管上部署了一切,发生了一些非常奇怪的事情。当我进入我的页面时,会出现https://accounts.google.com页面...
有一些很长的链接:
https://accounts.google.com/signin/v2/identifier?
service=ah&passive=true&continue=https%3A%2F%2Fappengine.google.com
%2F_ah%2Fconflogin%3Fcontinue%3Dhttps%3A%2F%2Fus-central1-treebase-
b21-d5.cloudfunctions.net%2Fssrapp%2F&flowName=GlifWebSignIn&flowEntry=
ServiceLogin&hl=en-GB
这可能是什么原因造成的?怎么解决?谢谢!
负责SSR的index.js
文件:import React from 'react';
import { renderToString } from 'react-dom/server';
import express from 'express';
import App from './app/containers/App';
import functions from 'firebase-functions';
const app = express();
app.get('**', (req, res) => {
const html = renderToString(<App />);
res.set('Cache-Control', 'public, max-age=600, s-maxage=1200');
res.send(`
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div id="app">${html}</div>
<div id="fb-root"></div>
<script type="text/javascript" src="/main.30e39d69fe1ce70d8983.js"></script>
</body>
</html>
`);
});
export const ssrapp = functions.https.onRequest(app);
firebase.json
{
"hosting": {
"public": "build",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"function": "ssrapp"
}
]
}
}
答案 0 :(得分:1)
如果您使用HTTP函数提供动态内容以进行托管,则必须使用us-central1
答案 1 :(得分:0)
@Utwo是正确的。而且,如果您仍然不想在功能中使用us-central1或不想与firebase.json混为一谈,则可以在firebase函数中启用CORS。这样,浏览器也将允许从其他域调用这些功能。
exports.getData = functions.region("asia-east2").https.onRequest((req, res) => {
// browsers like chrome need these headers to be present in response
res.set("Access-Control-Allow-Origin", "*"); // you can also whitelist specific domain like "http://127.0.0.1:4000"
res.set("Access-Control-Allow-Headers", "Content-Type");
// your code starts here
//send response
res.status(200).send();
});
此功能将部署在https://asia-east2-your-project.cloudfunctions.net上,但您可以从托管在其他域上的应用程序/网站调用此功能
答案 2 :(得分:0)