ppo*_*ani 1 strongloop loopbackjs
我需要找到一种方法来更改从自定义远程方法发送的响应的内容类型。看来默认情况下它是application/json。
我有一个返回图像的远程方法,因此我需要以某种方式更改内容类型。
注册远程钩子,然后从上下文对象中设置类似 Express 的标头res。最后调用下一个函数(如果定义了)继续执行。
Model.afterRemote('fetch', function(ctx, instance, next) {
ctx.res.header('Content-Type', 'image/png');
next && next();
});
Run Code Online (Sandbox Code Playgroud)