我的 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 托管上的请求?我知道在函数内部是可能的,但我很想在托管配置上这样做。
如何在以下节点响应中为我下载的二进制文件设置文件名以获取请求,现在它下载文件并将其名称设置为 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)