Does the app.use function take in every type of request?
…as opposed to say, app.get which takes in only get requests?
Does the app.use function take in every type of request?
…as opposed to say, app.get which takes in only get requests?
It only tests for the path (string/regex/array, that is, if supplied).
Docs: app.use
app.use([path,] callback [, callback...])
Mounts the specified middleware function or functions at the specified path: the middleware function is executed when the base of the requested path matches path.
You can apply middleware to specific routes by chaining them, here is the cors example from the docs.
Enable CORS for a Single Route
app.get('/products/:id', cors(), function (req, res, next) { res.json({msg: 'This is CORS-enabled for a Single Route'}) })
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.