How can I wrap each API response into a standard reply object in SailsJS?

妖精的绣舞 提交于 2019-12-05 05:26:34

Sails custom responses are great for this.

If you look at the blueprint code, you'll see that each one calls res.ok when it's done: https://github.com/balderdashy/sails/blob/master/lib/hooks/blueprints/actions/find.js#L63

You can add your own file - ok.js - to api/responses/ - which will override the default built in handler.

https://github.com/balderdashy/sails/blob/master/lib/hooks/responses/defaults/ok.js <- just copy and paste this to start, and adapt as you need.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!