koa-static 一些问题处理

再次复习koa-static 我发现改版了,一些代码改了

const Koa = require('koa')
const static = require('koa-static')
const router = require('koa-router')()

const server = new Koa();
router.get('/', async ctx => {
    ctx.body = "//html"
});
router.all(/((\.jpg)|(\.png)|(\.gif))$/i, static('./static', {
    maxage: 5 * 86400 * 1000
}));
router.all(/((\.js)|(\.jsx))$/i, static('./static', {
    maxage: 2 * 86400 * 1000
}));
router.all(/(\.css)$/i, static('./static', {
    maxage: 3 * 86400 * 1000
}));
router.all(/((\.html)|(\.htm))$/i, static('./static', {
    maxage: 2 * 86400 * 1000
}));
router.all('*', static('./static', {
    maxage: 3 * 86400 * 1000
}));

server.use(router.routes())
// server.use(static('./static', {
//     maxage: 1 * 86400 * 1000
// }))

server.listen(3000)

上面一运行就会报错

其中报错的代码是:

这句报错了,所以我将这句去掉了

但是当我去访问一些没有设定扩展名的文件时,找不到资源

所以这个时候我要特别处理下

扫描二维码关注公众号,回复: 11700975 查看本文章

猜你喜欢

转载自blog.csdn.net/qq_15009739/article/details/108156198