Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.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
Node.js:res.send在signedUrl字符串上返回生产中的{}_Node.js_Amazon Web Services_Express_Digital Ocean - Fatal编程技术网

Node.js:res.send在signedUrl字符串上返回生产中的{}

Node.js:res.send在signedUrl字符串上返回生产中的{},node.js,amazon-web-services,express,digital-ocean,Node.js,Amazon Web Services,Express,Digital Ocean,我正在尝试构建一个托管在PaaS服务数字海洋应用程序平台上的小型Node.js API。API非常简单:我知道只有一条路径是可以访问的。然而,我在这条路线中所做的工作只在我的机器处于开发模式时起作用。当我部署它时,它会停止我想要的工作 对于更多上下文,此路由采用字符串路径并将签名URL返回到我的Cloudfront实例。我正在使用aws cloudfront标志库,我试图在调用cfsign.getSignedUrl后直接返回已签名的URL。在开发和我的机器上,我确实收到了一个有效的URL。但是在

我正在尝试构建一个托管在PaaS服务数字海洋应用程序平台上的小型Node.js API。API非常简单:我知道只有一条路径是可以访问的。然而,我在这条路线中所做的工作只在我的机器处于开发模式时起作用。当我部署它时,它会停止我想要的工作

对于更多上下文,此路由采用字符串路径并将签名URL返回到我的Cloudfront实例。我正在使用aws cloudfront标志库,我试图在调用
cfsign.getSignedUrl
后直接返回已签名的URL。在开发和我的机器上,我确实收到了一个有效的URL。但是在部署和生产中,我只在访问URL后收到
{}

我通过快速res.send()调用验证了
signingParams
是否正确实例化并正确包含我的私钥。imagePath参数也是如此

以下是路线:

“严格使用”;
//感谢:https://aws.amazon.com/fr/blogs/developer/creating-amazon-cloudfront-signed-urls-in-node-js/
//而且:https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-creating-signed-url-canned-policy.html#private-创建签名的内容策略
const express=要求(“express”);
const router=express.router();
const cfsign=require('aws-cloudfront-sign');
常数两分钟=2*60*1000;
let key=“”
if(process.env.NODE_env=='development'){
key='localOnlyKey';
}else if(process.env.NODE_env=='production'){
key=process.env.CLOUDFRONT\u API\u SECRET;
}
/*
将图像路径转换为完整的Cloudfront URL
*/
路由器.get(“/:imagePath)”,(请求、恢复、下一步)=>{
const expirationTime=Date.now()+两分钟;
常量签名参数={
keypairId:'K34YSMTSIK8T2F',
privateKeyString:key,
过期时间:过期时间
};
常量imagePath=req.params.imagePath;
//生成签名URL
const signedUrl=cfsign.getSignedUrl(
`https://d3dzfh5brk23pn.cloudfront.net/${req.params.imagePath}`,
签名参数
);
res.send(signedUrl);
});
module.exports=路由器;
什么会导致此路由只产生一个
{}
响应


提前感谢。

CLOUDFRONT\u API\u SECRET
提供了吗?是的,它看起来解释正确,因为如果我执行
res.send(signingParams)
操作,它们将正确返回。包括
CLOUDFRONT\u API\u SECRET
注意
CLOUDFRONT\u API\u SECRET
值中的任何空格。空格字符在私钥字符串中是不合法的。哦,我想就是这样……我刚刚停止使用CLOUDFRONT_API_SECRET,这就解决了它!谢谢你的建议