使用
在脚本所在目录新建www目录,新建1.txt,在浏览器中请求http://localhost:8080/1.txt
const Koa = require('koa');
const path = require('path');
const staticCache = require('koa-static-cache');
const server = new Koa();
server.listen(8080);
server.use(
staticCache(path.resolve("www"), {
maxAge: 365 * 24 * 60 * 60
})
);
本文介绍如何使用Koa框架创建一个简单的静态文件服务器。在脚本所在目录下新建www目录及1.txt文件,通过koa-static-cache中间件实现缓存功能,使浏览器能够通过http://localhost:8080/1.txt请求到该文件。

250

被折叠的 条评论
为什么被折叠?



