Limit express bus to specific routes

I set up downloading files using express busboy, using the example from the repository here which does not seem to use the usual syntax use(), so I got a little confused about how to actually limit this middleware, so it only runs on a specific route, as it violates other POST requests.

Here's how I set it up:

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

busboy.extend(app, {
    upload: true,
    path: './uploads/temp'
});
+4
source share
3 answers

Well, since express-busboy didn't work for me, I tried using express-fileupload instead, and now it works.

0

allowedPath regex -, -. /

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

Try using Multer and limit it to the route:

app.post('/^\/api\/ccUpload$/',
  multer({
    dest: './uploads/temp',
    rename: function(fieldname, filename, req, res) {
      return filename.toLowerCase();
    }
  }),
  yourRouteHandler
);
0
source

Source: https://habr.com/ru/post/1652725/


All Articles