A
A
Alexander2021-12-01 17:32:23
Express.js
Alexander, 2021-12-01 17:32:23

How to return 304 status in express?

I wrote a condition to return a 304 status and added a test header to see if my condition actually works.

app.get('/', (req, res, next) => {
  const modifiedSince = req.get('If-Modified-Since')
  
  if (modifiedSince) {
    res.append('Test-Header', '*');
    res.status(304).end();
  } else {
    res.sendFile(path.join(__dirname + '/index.html'));
  }
})


The title is added (screenshot - joxi.ru/EA4GNNzhv1ld32), but the status code is still 200, why is that?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question