const serve = require("koa-static");
const Router = require("koa-router");
app.use(serve("../static", {
/* 文件的超时时间 */
maxage: 7 * 24 * 60 * 60 * 1000,
/* 根文件 */
index: "index.html",
}))
/* 根据router判断文件类型赋予不同的缓存时间 */
let staticRouter = new Router();
staticRouter.all(/(\.jpg|\.png|\.gif)$/i, serve("./static", {
maxage: 60 * 24 * 60 * 60 * 1000
}))
staticRouter.all(/(\.css)$/i, serve("./static", {
maxage: 1 * 24 * 60 * 60 * 1000
}))
staticRouter.all(/(\.html|\.htm|\.shtml)$/i, serve("./static", {
maxage: 20 * 24 * 60 * 60 * 1000
}))
staticRouter.all("", serve("./static", {
maxage: 30 * 24 * 60 * 60 * 1000
}))