gpt4 book ai didi

javascript - Firebase 函数 - 如何在 index.js 中包含外部 style.css

转载 作者:行者123 更新时间:2023-12-03 02:01:07 26 4
gpt4 key购买 nike

外部 style.css 文件在服务器上部署后不起作用

我的index.js和styles.css位于同一目录中。

index.js

const functions = require('firebase-functions');

exports.helloWorld = functions.https.onRequest((request, response) => {
response.send(
`<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
Hello ...
</body>
</html>
`);
});

最佳答案

默认情况下,Cloud Functions HTTP 触发器不提供静态内容(例如 HTML、CSS 和 JS 文件)。 HTTP 触发器主要供您编写响应 HTTP 请求的代码,例如 API 调用。

如果您想与 HTTP 请求一起提供静态内容,您应该考虑使用 Firebase Hosting以及云功能。 Firebase Hosting 将提供您的静态内容,并且当 configured properly ,它还会将一些 URL 转发到可由您编写的代码提供服务的 Cloud Functions。

您的另一个选择是在 Cloud Functions 中配置快速应用程序,并使用它设置一些路由,以便您使用函数部署的内容可以为直接发送到 Cloud Functions 的传入请求提供服务。但我认为使用 Firebase Hosting 可能是更常见和有用的选项。

关于javascript - Firebase 函数 - 如何在 index.js 中包含外部 style.css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50022909/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com