I have an array:
var arr = ["/index.html", "/alternative_index.html", "/index"]
and I want the Express server to return the same thing for all these routes:
localhost:8080/index.html
localhost:8080/alternative_index.html
localhost:8080/index
This works:
app.get("/index.html|/alternative_index.html|/index", (req, res) => {
console.log("Here")
...
}
So I defined a variable that is the same as the route above:
// returns "/index.html|/alternative_index.html|/index"
var indexRoutes = arr.join("|")
However, this does not work:
app.get(indexRoutes, (req, res) => {
console.log("Here")
...
}
I also tried using a RegExp
for indexRoutes
and that also did not work.
Why is Express not registering the right route when I define it using a variable?