过去一个月我一直在研究这个问题,但没有找到任何有用的解决方案。我目前正在尝试使用 firebase 函数以及 express.js 和 EJS 视图引擎来托管网站。
我将讨论将静态 CSS 文件提供给 EJS 文件的问题。我已经看遍了,但似乎找不到任何有帮助的正确答案。
我有以下文件结构(在函数文件夹内):
这是我的 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");
}) …Run Code Online (Sandbox Code Playgroud)