Firebase功能:重写不执行任何操作

时间:2018-03-11 15:14:21

标签: angular firebase google-cloud-functions

我尝试按照本教程设置一个包含Angular Universal(服务器端渲染包)的博客:https://hackernoon.com/deploy-angular-universal-w-firebase-ad70ea2413a1

/ dist文件夹似乎得到了服务,如果我不从中删除index.html,它会正确地提供非预呈现的应用程序。但是为了获得预呈现的应用程序,我应该删除index.html。正如我在控制台输出中看到的那样,这也有效 - 我得到了像

这样的调用
[hosting] Rewriting / to live function ssr
[hosting] Rewriting /favicon.ico to live function ssr

但他们都过得很快。我以为我的index.js有问题,所以我用虚拟替换它(来自google的firebase教程):

const functions = require('firebase-functions');
exports.ssr = 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>`);
});

仍然没有回复,我在浏览器中得到超时。当我做curl -v时,我得到了:

curl http://localhost:5000 -v
* Rebuilt URL to: http://localhost:5000/
*   Trying ::1...
* TCP_NODELAY set
* Connection failed
* connect to ::1 port 5000 failed: Connection refused
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 5000 (#0)
> GET / HTTP/1.1
> Host: localhost:5000
> User-Agent: curl/7.54.0
> Accept: */*
>
< HTTP/1.1 504 Gateway Timeout
< Date: Sun, 11 Mar 2018 15:12:11 GMT
< Connection: keep-alive
< Content-Length: 42
<
* Connection #0 to host localhost left intact
Timed out waiting for function to respond

我如何继续调试这个?我正在使用firebase serve在本地测试所有内容,但我在远程部署上遇到了同样的问题

1 个答案:

答案 0 :(得分:1)

firebase serve --only functions,hosting怎么样? AFAIK firebase serve仅运行未设置功能的主机模块(即使它们已在配置中指定)。