Ilja Ilja - 1 year ago 45
Node.js Question

Is there a way to check post to 1 url or the other in express?

I am currently proxying my session creation url with express in a way like this:'/sessions', (req, res) => {
// Logic here

Logic that goes into this proxy also repeats for my
endpoint, hence I would not want to rewrite it instead I'd want above
to also check for my second url, is this possible?

Answer Source

From the documentation for

The path for which the middleware function is invoked; can be any of:

  • A string representing a path.
  • A path pattern.
  • A regular expression pattern to match paths.
  • An array of combinations of any of the above.

which means you can actually pass in an array of paths['/sessions', '/confirmation'] , (req, res) => {
    // Logic here