Firebase重写在托管站点上不起作用[关闭]

问题描述 投票:0回答:1

我一直在尝试在Firebase托管站点上重写Firebase。不管我尝试什么都行不通。现在,我将所有重写都路由到名为app的路由功能中。正如您在下面看到的>>

firebase.json

     {
            "public": "public/dist-main",
            "target": "public-store-easy",
            "ignore": [
                "firebase.json",
                "**/.*",
                "**/node_modules/**"
            ],
            "rewrites": [
                {
                    "source": "/**",
                    "function": "app"
                }
            ]
        },

这是我的路由功能>>

const functions = require('firebase-functions');
const express = require('express');
const path = require('path');
const html = require('html')
const app = express();
app.use(express.static('/../public/'));

app.get('/', (req, res) => {
    res.sendFile('/dist-main/index.html', { root: '../public' })
})
app.get('/login', (req, res) => {
    res.sendFile('/dist-main/login.html', { root: '../public' })
})
app.get('/HOME', (req, res) => {
    res.sendFile('/dist-main/home.html', { root: '../public' })
})
app.get('/feedback', (req, res) => {
    res.sendFile('/dist-main/feedback-form.html', { root: '../public' })
})
exports.app = functions.https.onRequest(app);

我希望它能正常工作,因为它在我的本地主机服务器和firebase服务服务器上也能正常工作。

提前谢谢!

node.js firebase express google-cloud-functions firebase-hosting
1个回答
0
投票

[部署的Cloud Functions只能访问functions目录中的文件。您正在尝试从未部署功能的../public发送文件。

[如果您希望此方法起作用,则需要将public目录移到functions目录内,并适当地更新{"hosting": {"public": ""}}键。

© www.soinside.com 2019 - 2024. All rights reserved.