Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase云功能与Firebase主机:Firebase.json“;重写;_Firebase_Google Cloud Functions_Firebase Hosting - Fatal编程技术网

Firebase云功能与Firebase主机:Firebase.json“;重写;

Firebase云功能与Firebase主机:Firebase.json“;重写;,firebase,google-cloud-functions,firebase-hosting,Firebase,Google Cloud Functions,Firebase Hosting,我正在尝试使用云函数创建动态页面,但当我在本地使用cli时,我会从公用文件夹获取index.html页面 我尝试部署功能,在firebase中托管,但问题仍然存在,我是从公用文件夹获取index.html页面的 所以对于我来说,我在尝试下面的代码——我想我一定是弄错了“重写”部分 /functions/index.js const functions = require('firebase-functions'); exports.bigben = functions.https.onRequ

我正在尝试使用云函数创建动态页面,但当我在本地使用cli时,我会从公用文件夹获取index.html页面

我尝试部署功能,在firebase中托管,但问题仍然存在,我是从公用文件夹获取index.html页面的

所以对于我来说,我在尝试下面的代码——我想我一定是弄错了“重写”部分

/functions/index.js

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

exports.bigben = functions.https.onRequest((req, res) => {
  const hours = (new Date().getHours() % 12) + 1 // london is UTC + 1hr;
  res.status(200).send(`<!doctype html>
    <head>
      <title>Time</title>
    </head>
    <body>
      ${'BONG '.repeat(hours)}
    </body>
  </html>`);
});
我想做的是当我们击中时,我们必须得到bigben函数的响应数据


请有人举手

出于性能原因,Firebase主机总是更喜欢静态内容的精确匹配,而不是重写。从公共目录中删除
index.html
,您的重写应该可以开始了。

谢谢@Michael Bleigh,从公共目录中删除index.html后,我从函数中获得了res。我知道这很旧,但我只想指出,这不适用于单页应用程序。不过,解决方法很简单。。。在全局重写之前插入重写的函数:)
{
  "hosting": {
    "public": "public",

    // Add the following rewrites section *within* "hosting"
   "rewrites": [ {
      "source": "/", "function": "bigben"
    } ]

  }
}