[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
44 lines (28 loc) · 1.07 KB

middleware.md

File metadata and controls

44 lines (28 loc) · 1.07 KB

koa-static中间件使用

使用例子

demo源码

https://github.com/ChenShenhai/koa2-note/blob/master/demo/static-use-middleware/

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

const app = new Koa()

// 静态资源目录对于相对入口文件index.js的路径
const staticPath = './static'

app.use(static(
  path.join( __dirname,  staticPath)
))


app.use( async ( ctx ) => {
  ctx.body = 'hello world'
})

app.listen(3000, () => {
  console.log('[demo] static-use-middleware is starting at port 3000')
})

效果

static-server-result

static-server-result

static-server-result