A
A
Alexander Koshelev2018-11-08 23:22:49
Node.js
Alexander Koshelev, 2018-11-08 23:22:49

What is the correct way to cache-control in the get request of a node.js application?

Good evening, please tell me how to correctly arrange caching in a get request?
Found this solution

var options = {host:'host.com',path:urlPath,headers:{'Cache-Control':'no-cache'}}
http.get(options, function(res){
    //
});

But I don't want to use it because I have to create my own options variable for each get request, how can I add headers:{'Cache-Control':'.......'} header to my code?
router.get('/path', async (req, res) => {
  res.render('.......');
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Abcdefgk, 2018-11-09
@Xandr24

Well, this is kakbe materiel - to make a midlover.
Copy this to the "main file" before the routes

app.use(function(req, res, next) {
  res.setHeader('Cache-Control', 'no-cache');
  next();
});

Total business.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question