Created
August 23, 2020 01:27
-
-
Save standinga/d18ff10c5c122eb80df68476da6d20d1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express') | |
const app = express() | |
const port = 3000 | |
const increment = function () { | |
counter ++ | |
setTimeout(increment, 1000); | |
} | |
var maxAge = 4 | |
increment() | |
var counter = 0 | |
app.get('*', (req, res) => { | |
console.log(`Counter: ${counter}, request cache policy: ${req.headers['cache-policy']}`) | |
res.set('Cache-Control', `public, max-age=${maxAge}`) | |
res.set(`Etag`, `${Math.floor(counter / 2)}`) | |
res.send(`Counter: ${counter}`) | |
}) | |
app.listen(port, ()=> console.log(`listening at http://0.0.0.0:${port}`)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment