Add cache-control header to statics

pull/282/head
Amio 2019-06-07 20:34:26 +08:00
rodzic 36d6496912
commit 9a084f4fd8
1 zmienionych plików z 11 dodań i 3 usunięć

Wyświetl plik

@ -23,15 +23,23 @@ const isStatic = (url) => {
return false
}
const serveStaticHeaders = [
{
source: "**/*",
headers: [{
key: "Cache-Control",
value: "public, max-age: 86400, s-maxage: 86400"
}]
}
]
const { PUB_DIR = '.' } = process.env
const server = http.createServer(async (req, res) => {
// handle statics
if (isStatic(req.url)) {
return serveHandler(req, res, {
public: path.resolve(__dirname, PUB_DIR),
headers: [
{ "source": "**/*", "headers": "public, max-age: 86400, s-maxage: 86400" }
]
headers: serveStaticHeaders
})
}