使用 angularjs 快速托管 firebase - 服务器端渲染不工作

firebase hosting in express with angularjs - server side rendering is not working

我有一个 firebase 应用程序,后端是 express,前端是 angularjs。 这个应用程序有管理仪表板和客户端页面,目录结构如下

App - functions
       --admin
          ---app
          ---controllers
          ---views
       --client
          ---app
          ---controllers
          ---views
       --index.js
    -public
      --assets
        ---images
        ---stylesheets
        ---javascripts

这是我的 index.js 表示

const functions           = require('firebase-functions');
const admin      = require('firebase-admin');
const express     = require('express');
const path        = require('path');
const bodyParser     = require('body-parser');
const cookieParser    = require('cookie-parser');
const serviceAccount    = require('./service_account.json');

const app            = express();
const firebaseApp       = admin.initializeApp({
        credential: admin.credential.cert(serviceAccount),
        databaseURL: "https://lelangawi.firebaseio.com"
    });

app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({ extended: true })); // for parsing
app.use(cookieParser());

app.set('views', __dirname);
app.use('/assets', express.static(path.join(__dirname + '../../public/assets')));
app.use('/admin/app', express.static(path.join(__dirname + '../../functions/admin/app')));
app.use('/client/app', express.static(path.join(__dirname + '../../functions/client/app')));
app.use('/admin/controllers', express.static(path.join(__dirname + '../../functions/admin/controllers')));
app.use('/client/controllers', express.static(path.join(__dirname + '../../functions/client/controllers')));


app.engine('html', require('ejs').renderFile);

// CORS Support
app.use(function(req, res, next) {
    res.header('Access-Control-Allow-Origin', '*');
    res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
    res.header('Access-Control-Allow-Headers', 'Content-Type');
    next();
});

app.get('/admin', function (req, res) {
    res.set('Cache-Control', 'public, max-age=300, s-maxage=600');
    res.render('admin/views/index.html');
});

app.get('/', function (req, res) {
    res.set('Cache-Control', 'public, max-age=300, s-maxage=600');
    res.render('client/views/index.html');
});

app.get('/admin/partials/:name', function (req, res) {
    res.set('Cache-Control', 'public, max-age=300, s-maxage=600');
    res.render('admin/views/partials/' + req.params.name);
});

app.get('/client/partials/:name', function (req, res) {
    res.set('Cache-Control', 'public, max-age=300, s-maxage=600');
    res.render('client/views/partials/' + req.params.name);
});



exports.app = functions.https.onRequest(app);

每次我 运行 在控制台中命令 firebase 服务时,都会出现错误:无法获取 url。但它适用于应用 url

这是托管 url:http://localhost:5000

这是函数 url : http://localhost:5001/lelangawi/us-central1/app/

要配置托管路由,您必须更改文件 firebase.json

上的托管规则
"hosting": {
"public": "public",
"ignore": [
  "firebase.json",
  "**/.*",
  "**/node_modules/**"
]}

然后改成这个

"hosting": {
"public": "public",
"ignore": [
  "firebase.json",
  "**/.*",
  "**/node_modules/**"
],
"rewrites": [
  {
    "source": "**",
    "function": "app"
  }
]}