我试图通过“razzle”帮助工具使用 create-React 基础知识制作一个react SSR 网站。
该应用程序最初用于此:
'use strict'
const functions = require('firebase-functions');
const app = require('./server/build/server.bundle.js').default;
exports.app = functions.https.onRequest(app)
但是当我把它改成这样时:
'use strict'
const functions = require('firebase-functions');
const App = require('./server/build/server.bundle.js').default;
const React = require('react')
const express = require('express');
const fs = require('fs');
const app = express();
const {RenderToString} = require('react-dom/server');
const index = fs.readFileSync(__dirname +'/index.html', 'utf8');
app.get ('**', (req, res) => {
const html = RenderToString(App);
const finalHtml = index.replace('<!-- ::APP:: -->', html)
res.set('Cache-Control', 'public, max-age=600, sMax-age=1200');
res.send(finalHtml);
})
exports.shell = functions.https.onRequest(app);
而不是我得到的网站
一个应用程序正在请求访问您的 Google 帐户的权限。请选择您要使用的帐户。
并尝试使用 firebase admin gmail 帐户登录时:
错误:禁止您的客户端无权从此服务器获取 URL /app/。
我做错了什么,我该如何解决?
原来的 SSR 功能被移除,新的exports.shell 成功添加。