小编Dag*_*adu的帖子

Firebase 托管:检测社交媒体爬虫机器人,如 facebook、twitter 和 google

我的 firebase 托管设置目前正在像这样重定向到 index.html。

{
  "database": {
    "rules": "database.rules.json"
  },
  "hosting": {
    "public": "build",
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      },
      {
        "source": "/details/**",
        "function": "details"
      }
    ]
  }
}
Run Code Online (Sandbox Code Playgroud)

但我想根据 Facebook 的 Facebot 等用户代理重定向请求......

有没有办法在到达云功能之前重定向 Firebase 托管上的请求?我知道在函数内部是可能的,但我很想在托管配置上这样做。

facebook node.js firebase firebase-hosting

8
推荐指数
1
解决办法
558
查看次数

在 node.js 中设置下载响应的文件名

如何在以下节点响应中为我下载的二进制文件设置文件名以获取请求,现在它下载文件并将其名称设置为 req.url 字符串

.get(function (req, res) {
  var filename = path.join(process.cwd(), '');
  path.exists(filename, function (exists) {
    if (!exists) {
      res.writeHead(404, {
        "Content-Type": "text/plain"
      });
      res.write("File Not found: 404 Not Found\n");
      res.end();
      return;
    }

    if (fs.statSync(filename).isDirectory()) {
      filename += '/' + category + '/' + 'undo.png';
    }

    fs.readFile(filename, "binary", function (err, file) {
      if (err) {
        res.writeHead(500, {
          "Content-Type": "binary"
        });
        res.write(err + "\n");
        res.end();
        return;
      }

      res.writeHead(200);
      res.write(file, "binary");
      res.end();
    });
  });
});
Run Code Online (Sandbox Code Playgroud)

javascript http node.js

5
推荐指数
1
解决办法
7396
查看次数