我想按照下面的方式与ExpressJS组成的REST API响应一起发送数据和消息。
main.js
...
global.RES = require(./response);
...
response.js
exports.SUC_FIND = {
resCode: '100',
message: 'Successfully Find Post'
}
API
...
let result = [Post List]
res.send( ? )
// Expected Response in Client
/*
console.log(response.data.resCode) // '100'
console.log(response.data.message) // 'Success ...'
console.log(response.data.result) // [Post List]
*/
...
这是怎么做的?
答案 0 :(得分:0)
我并没有完全理解你的意思,但我相信你提到了这样的话
response.js
var SUC_FIND = {
resCode: '100',
message: 'Successfully Find Post'
}
module.exports=SUC_FIND;
API
var RES = require(./response);
let result = [Post List]
res.send( {...RES, result} )