8000 GitHub - justan/koa-page: Koa middleware for serve path with javascript file
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

justan/koa-page

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

koa-page

npm GitHub Codecov

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

About

Koa middleware for serve path with javascript file

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  
0