[tools/gulp-serve:feat] make responses cacheable
This commit is contained in:
parent
f185489b1b
commit
029869f8a0
11
gulpfile.js
11
gulpfile.js
|
@ -333,11 +333,18 @@ const serve = (done) => {
|
|||
|
||||
const handler = (allowedOrigin) => async (req, res) => {
|
||||
console.log(`${new Date().toISOString()} ${req.method} ${req.url}`) // eslint-disable-line no-console
|
||||
res.writeHead(200, {
|
||||
try {
|
||||
res.sendFile(path.resolve(__dirname, "build", paths.scriptOut), {
|
||||
headers: {
|
||||
"Content-Type": "text/javascript; charset=UTF-8",
|
||||
"Access-Control-Allow-Origin": allowedOrigin,
|
||||
},
|
||||
maxAge: 2000,
|
||||
})
|
||||
res.end(await fs.readFile(path.join("build", paths.scriptOut)))
|
||||
} 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"))
|
||||
|
|
Loading…
Reference in New Issue