05-静态资源托管中间件

nobility 发布于 2025-09-02 02-Koa2 1082 次阅读


静态资源托管中间件

Koa并没有捆绑任何中间件,静态资源托管中间件需要独立安装,使用npm install koa-static安装静态资源托管中间件,之后使用与express使用方式一致了

const path = require("path");
const static = require('koa-static')
app.use(static(path.join(__dirname, "public"), {
    index: "index.html",	//默认首页
    maxAge: 24 * 60 * 60 * 1000	//将静态文件缓存浏览器的时间,单位毫秒
}));
加油啊!即便没有转生到异世界,也要拿出真本事!!!\(`Δ’)/
最后更新于 2025-09-02