Mushy Avocado
Mushy Avocado

Reputation: 139

Express app.get() detect all requests for certain file extensions?

I want to be able to handle requests for any request for a .html file type. Is this possible?

Something like this:

// server.js
app.get('/*.html', (req, res) => {
  // do something whenever a request is made for an html file
});

Upvotes: 0

Views: 749

Answers (1)

Vincent Menzel
Vincent Menzel

Reputation: 1055

You can use regex to match the path that you want like so. You can find more about routing here https://expressjs.com/en/guide/routing.html.

app.get(/.*\.html$/, (req, res) => {
  // do something whenever a request is made for an html file
});

Upvotes: 1

Related Questions