原生koa2实现静态资源服务器
https://chenshenhai.github.io/koa2-note/note/static/server.html
使用koa-static-cache中间件
例子代码:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22const Koa = require('koa2')
const path = require('path')
const static = require('koa-static-cache')
const app = new Koa()
//静态资源目录对于入口文件的相对路径
const staticPath = './static'
app.use(static(
'./static',{
prefix:'/'
}
))
// app.use(async ctx =>{
// ctx.body = 'hello world'
// })
app.listen(3000,()=>{
console.log('static is running at port 3000')
})
评论加载中