【发布时间】:2021-01-24 12:05:35
【问题描述】:
我创建了以下 express API
const express = require("express");
const app = express();
const bodyParser = require("body-parser");
const cookieParser = require("cookie-parser");
require("dotenv/config");
//routes
const authRoute = require("./routes/auth.js");
const adminRoute = require("./routes/admin.js");
//middleweres
//converting body into json using body parser
app.use(cookieParser());
app.use(bodyParser.json());
app.use("/", express.static("public"));
app.use("/api/auth", authRoute);
app.use("/api/admin", adminRoute);
// starting express server
// app.listen(5000, () => {
// console.log("listning on port 5000");
// });
module.exports = {
app,
};
在公共文件夹中,我在公共/静态文件夹中有 html 文件和 css 和 js 公共文件夹中的 html、css 和 js 是通过 react build 生成的。 我正在尝试使用以下命令在谷歌云功能中部署此 API
gcloud functions deploy outreach-dashboard --entry-point app --runtime nodejs10 --trigger-http --allow-unauthenticated
函数正在部署,但问题是当我在 gcp 仪表板上看到函数时,它的源代码不包含公用文件夹,如果我以 zip 格式下载源代码,那么我可以在那里看到公用文件夹,但它是空的。 我需要公用文件夹才能部署,以便使用
express.static("public")
【问题讨论】:
-
无静态路由有效吗?
-
不,他们没有我还发现通过从我的 .gitignore 文件中删除 /public 他们开始在 GCF 中弹出。但 GCF 仍然没有提供静态 html、css 并给我 403 错误,但我认为这是完全不同的问题
-
那么现在,您有 403 而不是 404?正确的?你还在使用 --allow-unauthenticated 参数吗?
-
是的,我仍在使用 --allow-unauthenticated 我觉得我应该在其他地方托管静态文件,并且只使用云功能来托管 API
-
如果我理解正确,您已将新文件部署到
public文件夹,但未部署。我在新的helloworld部署上尝试了这个,它工作正常。我可以在每次部署时添加和删除文件和目录,您的帐户一定有问题...我认为您应该寻求支持或尝试新项目
标签: node.js google-cloud-platform google-cloud-functions