node.js - Firebase 重写无法在托管站点上运行
问题描述
我一直在尝试让 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);
我希望它可以正常工作,因为它在我的 localhost 服务器和 firebase 服务器上都可以正常工作。
先感谢您!
解决方案
部署后,Cloud Functions 只能访问目录中的functions
文件。您正在尝试发送../public
未部署功能的文件。
如果你想让它工作,你需要在目录中移动public
目录functions
并适当地更新{"hosting": {"public": ""}}
密钥。
推荐阅读
- c - 试图打印一个无符号长,但得到一个不同的数字
- php - php,如何将具有多个表的数据库导出到具有多个工作表的单个excel文件中?
- python - 在 CPLEX Python 中限制根节点处理
- excel - 在matlab中转置数据块
- powershell - 使用 Powershell,如果用户输入不是数字或不是给定选项之一,则显示自定义消息
- azure-active-directory - Delve 用户配置文件和使用 Graph API 获取数据的问题
- javascript - 在新的 html 页面上加载新的 JavaScript 文件
- java - 数组列表 android
- reactjs - 如何处理通过componentDidMount来响应组件的异步数据
- installation - IBM Cloud Private 3.1.1 EE 安装错误