Javascript 如何部署react+;firebase主机上的express应用程序
我尝试使用firebase托管(使用express)来托管我的react应用程序 我选中了Javascript 如何部署react+;firebase主机上的express应用程序,javascript,node.js,reactjs,firebase,google-cloud-functions,Javascript,Node.js,Reactjs,Firebase,Google Cloud Functions,我尝试使用firebase托管(使用express)来托管我的react应用程序 我选中了函数/index.js。我想用'https://blahblahapp.web.app/chart,所以我使用路由器 //index.js 常量函数=需要(“firebase函数”); const express=要求(“express”); 常量app=express(); const cors=要求(“cors”); const bodyParser=require(“body parser”); co
函数/index.js
。我想用'https://blahblahapp.web.app/chart,所以我使用路由器
//index.js
常量函数=需要(“firebase函数”);
const express=要求(“express”);
常量app=express();
const cors=要求(“cors”);
const bodyParser=require(“body parser”);
const chart=require(“./routes/chart.js”);
const news=require(“./routes/news.js”);
const firebase=require(“firebase”);
var admin=require(“firebase admin”);
应用程序使用(cors());
use(bodyParser.json());
应用程序使用(“/图表”,图表)//问题一
//函数/routes/chart.js
//...
路由器.post(“/chart)”,(请求、回复)=>{
var公司代码=req.body.corp公司代码;
设结果=0;
如果(公司代码!==未定义){
结果=getStockInfo(公司代码);
res.json(结果);
}否则{
res.json({stocklist:0});
}
});
我还检查了firebase.json
{
"hosting": {
"public": "build",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "api"
}
]
}
}
我在这里取“/图表”
//src/Chart.js
常量fetchData=async(obj)=>{
const{corp_code,corp_name}=obj;
设结果=0;
const response=wait fetch(`/chart`{
方法:“张贴”,
标题:{“内容类型”:“应用程序/json”},
正文:JSON.stringify({
来自:“图表”,
公司名称:公司名称,
公司代码:公司代码,
}),
});
const stocklist=wait response.json();
返回库存清单[“库存清单”];
};
但是在npm运行构建
和firebase部署
之后,出现了404错误
/图表:1加载资源失败:服务器响应状态为404()
我真想知道我的代码出了什么问题。我想我尽了我所能,但仍然没有工作