gpt4 book ai didi

javascript - 渲染/包含 html 文件 Google Cloud Functions

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

我对 Google Cloud Functions 几乎是新手,我想知道是否有办法从函数渲染 html 文件。我有一个使用 send 方法来执行此操作的方法,但由于文件太长,最终代码非常长,我总是部署函数来修改最少的内容。有没有办法包含外部文件或类似的东西?在这种情况下,我不需要使用 JS 变量来修改文本,因为这是一个静态信息文件。现在我使用这个并且它有效:

  exports.index = functions.https.onRequest((req, res)=> { res.send(`<!doctype html>
<head>
<title>MY HTML</title>
<link rel="shortcut icon" href="https://firebasestorage.googleapis.com/v0/b/firebase-spot.com/o/favicon.ico?alt=media"/>
</head>
<body>
<div class='content'>...

是否有类似 include('http:\path\to\index.html') 的内容?

最佳答案

没有简单的函数可以做到这一点。您必须编写代码来发出 HTTP 请求来获取外部内容,下载它,然后将其发送到客户端。

关于javascript - 渲染/包含 html 文件 Google Cloud Functions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50694110/

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