koa-page

0.1.0 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i koa-page

Weekly Downloads

36

Version

0.1.0

License

MIT

Unpacked Size

9.59 kB

Total Files

14

Last publish

Collaborators

  • justan