Victoria
Victoria

Reputation: 335

Node JS Express Route Restrict issue

I'm trying to retrieve audio/image file from db.

app.use(restrictMiddleware());

Tho, because of the Route Restrict: It doesn't work. The question is, is there any other way to retrieve audio/image file from db so that it won't conflict with Authentication Route Restriction?

self.get = function (req, res) {
  let params = [
    req.params.record_id,
  ];
  db.query(`SELECT * ...`, params).then((data) => {
    console.log('result: ', data.rows.length);
    res.contentType('audio/mpeg');
    res.send(data.rows[0].audiofile);
  }).catch((err) => {
    res.status(500).end("Error:" + err);
  });

};

Upvotes: 0

Views: 275

Answers (1)

James
James

Reputation: 82096

Various ways of tackling this:

  • Simplest way is to declare the route before you call app.use(restrictMiddleware())
  • Cleanest way is probably go move all the secure routes into their own Router and only apply the restrictMiddleware to that, that way you can add non-secure routes easily
  • Alternatively, you could check for a specific URL / Header etc in the restrictMiddleware and skip when appropriate (not the nicest, but would do the job)

Upvotes: 1

Related Questions