【发布时间】:2019-06-26 07:03:54
【问题描述】:
过去一个月我一直在研究这个问题,但没有找到任何有用的解决方案。我目前正在尝试使用 firebase 函数以及 express.js 和 EJS 视图引擎来托管网站。
我将讨论将静态 CSS 文件提供给 EJS 文件的问题。我已经翻遍了,但似乎找不到任何有帮助的正确答案。
我有以下文件结构(在函数文件夹内):
- 公开
- 观看次数
- index.js
这是我的 index.js:
const functions = require('firebase-functions');
const express = require("express");
const ejs = require("ejs");
var path = require('path');
// // Create and Deploy Your First Cloud Functions
// // https://firebase.google.com/docs/functions/write-firebase-functions
//
// exports.helloWorld = functions.https.onRequest((request, response) => {
// response.send("Hello from Firebase!");
// });
var app = express();
app.set('view engine', 'ejs');
// app.use('/static', express.static('public'));
app.use(express.static(__dirname + "/public"));
app.get("/", (request, response) => {
response.render("test");
})
// app.listen(5000, () => {
// console.log("Active app on port 5000");
// });
exports.webApp = functions.https.onRequest(app);
它正在渲染的页面(test.ejs):
<html>
<head>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body></body>
</html>
最后是 style.css 文件:
html {
background-color: black;
}
(style.css 和 test.ejs 都是这样完成的,只是为了测试,因为我对所有这些都有很大的问题)
我在网上尝试了大多数解决方案,但所有这些解决方案都只能在本地运行 express.js 应用程序时工作,而不能通过 firebase 服务或部署命令。我对此完全迷失了,感谢您提供任何帮助。
【问题讨论】:
-
我在 Cloud Run 和 express 静态中间件中看到了这个问题。你最终找到解决方案了吗?
-
介意分享您的文件夹结构吗?谢谢。
-
您找到解决方案了吗?我不认为@zemunkh 的回答是正确的。
-
任何遇到此问题的人,请在此处查看我的问题和答案:stackoverflow.com/a/68346542?noredirect=1
标签: node.js express google-cloud-functions ejs