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

Time:01-11

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
});

CodePudding user response:

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
});

  •  Tags:  
  • Related