Maison > Questions et réponses > le corps du texte
我是用的koa-cache-control插件来设置cachecontrol的maxAge,不知道为什么照着API去做完全没有效果,始终maxAge=0.小白一枚求教
附git插件链接 https://github.com/DaMouse404...
var send = require('koa-send');
var Koa = require('koa');
var app = new Koa();
var Router = require('koa-router');
var cors = require('koa-cors');
var koaBody = require('koa-body')();
var cacheControl = require('koa-cache-control');
var router = new Router({
prefix: '/public'
});
app.use(gzip());
app.use(cors())
.use(router.routes())
.use(router.allowedMethods());
app.use(cacheControl({
maxAge: 500
}));
router.get('/:fname/:cname', koaBody, function*() {
var fname = this.params.fname;
var cname = this.params.cname;
console.log("文件类型" + fname);
console.log("文件名" + cname);
yield send(this, "./public/" + fname + "/" + cname);
})
var port = 8003;
app.listen(port);
console.log( 启动成功,端口: ${port});
第一次提问题,请多多指教