微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

TypeError:无法读取未定义的属性'expressMiddleware'

如何解决TypeError:无法读取未定义的属性'expressMiddleware'

发生错误

回调错误!抛向全局错误处理程序。 TypeError:无法 读取未定义的属性“ expressMiddleware” 在SwaggerRunner.create(/home/feel/cfeel-core/node_modules/feel-framework/src/modules/http_api/init_steps/bootstrap_swagger.js:318:33) 在/home/feel/cfeel-core/node_modules/swagger-node-runner/index.js:237:7

代码如下

/home/feel/cfeel-core/node_modules/feel-framework/src/modules/http_api/init_steps/bootstrap_swagger.js:318:33)

    // Swagger express middleware
    SwaggerRunner.create(swaggerConfig,(errors,runner) => {
        if (errors) {
            // Ignore unused deFinition warning
            errors.validationWarnings = _.filter(
                errors.validationWarnings,error => error.code !== 'UNUSED_DEFinitioN',);

            // Some error occurred in configuring the swagger
            if (!_.isEmpty(errors.validationErrors)) {
                logger.error('Swagger Validation Errors:');
                logger.error(errors.validationErrors);
            }

            if (!_.isEmpty(errors.validationWarnings)) {
                logger.error('Swagger Validation Warnings:');
                logger.error(errors.validationWarnings);
            }

            if (
                !_.isEmpty(errors.validationErrors) ||
                !_.isEmpty(errors.validationWarnings)
            ) {
                cb(errors);
                return;
            }
        }

        // Swagger express middleware
        const swaggerExpress = runner.expressMiddleware();//318:33
        
        // Check the response and act appropriately on error
        runner.on('responseValidationError',validationResponse => {
            // Todo: Troubleshoot why default validation hook considers json response as string response
            if (validationResponse.errors[0].code !== 'INVALID_RESPONSE_BODY') {
                logger.error('Swagger Response Validation Errors:');
                logger.error(validationResponse.errors[0].errors);
            }
        });

        // Install middleware
        swaggerExpress.register(app);

        // To be used in test cases or getting configuration runtime
        app.swaggerRunner = runner;

        // Managing all the queries which were not caught by prevIoUs middlewares.
        app.use((req,res,next) => {
            // We need to check if the response is already handled by some other middlewares/fittings/controllers
            // In case not,we consider it as 404 and send default response
            // res.headeRSSent is a patch,and only works if above middlewares set some header no matter the status code
            // Another possible workaround would be res.bodySize === 0
            if (!res.headeRSSent) {
                res.status(404);
                res.json({ description: 'Page not found' });
            }
            next();
        });

        swaggerHelper
            .getSchemaAsJSON()
            .then(resolvedSchema => {
                // Successfully mounted the swagger runner
                cb(null,{
                    swaggerRunner: runner,deFinitions: resolvedSchema.deFinitions,});
            })
            .catch(reason => {
                logger.error(reason.toString());
                cb(reason);
            });
    });
}

/home/feel/cfeel-core/node_modules/swagger-node-runner/index.js:237:7

    cb(null,self);
    })
    .catch(function(err) {
      cb(err);//237:7
    })

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。