Sails.js - 异步控制器无法绑定到路由

时间:2016-10-25 19:09:59

标签: javascript node.js sails.js

在Node.js 7.0发布之前,我的Sails.js控制器看起来类似于:

const _async = require('asyncawait/async');
const _await = require('asyncawait/await');

...

get: _async (function (req, res) {
    try {
        let item = _await (Items.find({
            id: req.params.id
        }));
        if (!item.length) {
            return res.notFound("The item does not exist");
        }
        return res.ok(item[0]);
    } catch (error) {
        return res.serverError(error);
    }
}),

以前的一切都很完美。在Node.js 7.0发布之后,我将其更改为:

 get: async function (req, res) {
    try {
        let item = await Items.find({
            id: req.params.id
        });
        if (!item.length) {
            return res.notFound("The item does not exist");
        }
        return res.ok(item[0]);
    } catch (error) {
        return res.serverError(error);
    }
},

但它记录错误:

error: In items.get, ignored invalid attempt to bind route to a 
non-function controller: { [Function: get] _middlewareType: 'ACTION: 
items/get' } for path:  /v1/items/:id and verb: get

修改 看起来像帆使用的下划线库中的错误:

if ( !_.isFunction(originalFn) ) {
        sails.after('lifted', function () {
          sails.log.error(
            'In '+controllerId + '.' + actionId+', ignored invalid attempt to bind route to a non-function controller:',
            originalFn, 'for path: ', path, verb ? ('and verb: ' + verb) : '');
        });
        return;
 }

记录了一个问题:https://github.com/balderdashy/sails/issues/3863

0 个答案:

没有答案