[tools/gulp-serve:feat] make responses cacheable

This commit is contained in:
Maddison Hellstrom 2020-11-19 23:39:27 -08:00
parent f185489b1b
commit 029869f8a0
1 changed files with 12 additions and 5 deletions

View File

@ -333,11 +333,18 @@ const serve = (done) => {
const handler = (allowedOrigin) => async (req, res) => { const handler = (allowedOrigin) => async (req, res) => {
console.log(`${new Date().toISOString()} ${req.method} ${req.url}`) // eslint-disable-line no-console console.log(`${new Date().toISOString()} ${req.method} ${req.url}`) // eslint-disable-line no-console
res.writeHead(200, { try {
"Content-Type": "text/javascript; charset=UTF-8", res.sendFile(path.resolve(__dirname, "build", paths.scriptOut), {
"Access-Control-Allow-Origin": allowedOrigin, headers: {
}) "Content-Type": "text/javascript; charset=UTF-8",
res.end(await fs.readFile(path.join("build", paths.scriptOut))) "Access-Control-Allow-Origin": allowedOrigin,
},
maxAge: 2000,
})
} catch (e) {
console.log(e) // eslint-disable-line no-console
res.status(500).send("Error reading config file.\n")
}
} }
app.get("/", handler("chrome-extension://mffcegbjcdejldmihkogmcnkgbbhioid")) app.get("/", handler("chrome-extension://mffcegbjcdejldmihkogmcnkgbbhioid"))