0.1.0 • Published 4 years ago
koa-page v0.1.0
koa-page
Serve path with a file.
Install
Using npm
npm i koa-page
Using yarn
yarn add koa-page
Usage
// app.js
const pt = require('path')
const App = require('koa')
const koaPage = require('koa-page')
const app = new App()
app.use(
koaPage({
pagePath: pt.join(__dir, 'views'),
})
)
app.listen(3000)
.
├── app.js
├── package.json
├── views
│ ├── index.js // curl http://127.0.0.0:3000/
│ ├── api.js // curl http://127.0.0.0:3000/api
| └── path
| └── to.js // curl http://127.0.0.0:3000/path/to
└── yarn.lock
API
koaPage(option = {}) {function}
Return a page router middleware.
app.use(
koaPage({
pagePath: pt.join(__dir, 'views'),
})
)
option.pagePath {string} path which view or controller
app.use(
koaPage({
pagePath: pt.join(__dir, 'views'),
})
)
option.prefix {string} match prefix
app.use(
koaPage({
prefix: '/path',
pagePath: pt.join(__dir, 'views'),
})
)
// matched http://host/path
option.middlewares {koa-middleware[]} middlewares
app.use(
koaPage({
pagePath: pt.join(__dir, 'views'),
middlewares: [],
})
)
License
MIT
0.1.0
4 years ago