SailsJS 中的 API 版本控制 [英] API Versioning in SailsJS

查看:58
本文介绍了SailsJS 中的 API 版本控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基于此问题,我禁用了嵌套控制器和蓝图.我的问题类似于

Based on this issue, I have nested controllers and blueprints are disabled. My issue is something like

api/控制器:v1/UserController.js

api/Controllers : v1/UserController.js

routes.js

      'POST /v1/user/register': 'v1/UserController.createUser'

政策.js

    'v1/UserController': {
    '*': [ 'passport'],
    createUser: ['ModelPolicy','AuditPolicy','reqBodyValidation']

如果是嵌套控制器:访问端点时:

If it is nested controller: while accessing the endpoint :

输出是一些东西:

    error: Sending 500 ("Server Error") response:
    Error: Invalid route option, "model".
    I don't know about any models named: `v1/user`

感谢解决.

推荐答案

我们实际上在我们的项目中做到了这一点,如果你在 JSON 对象中指定一个字符串文字作为控制器的键,你实际上可以做到这一点,如下所示:

We actually did this in our project, and you can actually do this if you specify a string literal as the key for the controller in the JSON object like so:

'v1/UserController' : {
  '*': [ 'passport'],
  createUser: ['ModelPolicy','AuditPolicy','reqBodyValidation']
}

这篇关于SailsJS 中的 API 版本控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆