当有人访问路由时,如何使用 Koa2 提供静态文件?我尝试了数以百万计的东西,但我总是收到未找到的消息。服务器已响应状态 404
import 'babel-polyfill'
import co from 'co'
import path from 'path'
import render from 'koa-swig'
import Koa from 'koa'
import Router from 'koa-router'
import serve from 'koa-static'
import convert from 'koa-convert'
import send from 'koa-send'
const app: Koa = new Koa()
const route: Routerr = new Router()
**example 1**
app.use(serve(path.resolve(__dirname + '/public/index.html')))
router.get('/lista', function *() {
console.log('Hello')
})
**example 2**
app.use(async (ctx) => {
await send(ctx, '/index.html', { root: '/public' })
})
router.get('/lista', function *() {
console.log('Hello')
})
app.use(router.routes())
app.use(router.allowedMethods())