[tools/gulp-serve:feat] make responses cacheable
This commit is contained in:
parent
f185489b1b
commit
029869f8a0
17
gulpfile.js
17
gulpfile.js
|
@ -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"))
|
||||||
|
|
Loading…
Reference in New Issue