最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

限制快递到特定路线

IT培训 admin 8浏览 0评论

限制快递到特定路线

我使用来自存储库here的示例使用express-busboy设置文件上传,其中似乎没有使用正常的use()语法,所以我对如何实际限制此中间件以使其仅在特定路由上执行感到困惑因为它打破了其他POST请求。

这是我配置它的方式:

var busboy = require('express-busboy');

busboy.extend(app, {
    upload: true,
    path: './uploads/temp'
});
回答如下:

在allowedPath值中,您可以在明确应用程序中定义的后路由中指定此案例限制中的正则表达式。喜欢/上传

busboy.extend(app, {
    upload: true,
    path: './uploads/temp',
    allowedPath: /^\/uploads$/

});

或者其他方面你可以通过功能

var options = {
        upload: true,
        path: './uploads/temp',


    };
options.allowedPath = function(url) {
    return url == '/api/ccUpload';
}

    busboy.extend(app, options);

限制快递到特定路线

我使用来自存储库here的示例使用express-busboy设置文件上传,其中似乎没有使用正常的use()语法,所以我对如何实际限制此中间件以使其仅在特定路由上执行感到困惑因为它打破了其他POST请求。

这是我配置它的方式:

var busboy = require('express-busboy');

busboy.extend(app, {
    upload: true,
    path: './uploads/temp'
});
回答如下:

在allowedPath值中,您可以在明确应用程序中定义的后路由中指定此案例限制中的正则表达式。喜欢/上传

busboy.extend(app, {
    upload: true,
    path: './uploads/temp',
    allowedPath: /^\/uploads$/

});

或者其他方面你可以通过功能

var options = {
        upload: true,
        path: './uploads/temp',


    };
options.allowedPath = function(url) {
    return url == '/api/ccUpload';
}

    busboy.extend(app, options);

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论