GithubHelp home page GithubHelp logo

koajs / resourcer-docs Goto Github PK

View Code? Open in Web Editor NEW
5.0 39.0 3.0 33 KB

[MAINTAINERS WANTED] Simple app that generates documentation for routes mounted using koa-resourcer.

License: MIT License

Makefile 5.40% JavaScript 94.60%

resourcer-docs's Introduction

#resourcer-docs

A simple documentation generator for koa-resourcer.

Use

In your app:

var koa = require('koa');
var join = require('path').join;
var resource = require('koa-resourcer');
var docs = require('koa-resourcer-docs');

var app = koa();
resource(app, join(__dirname, 'resources'), docs.addRoute);
app.listen();

In each resource app:

var koa = require('koa');
var Router = require('koa-joi-router');

var router = Router();
var app = module.exports = koa();

// Expose routes to documentation generator
app.routes = router.routes;

// Define some routes...

app.use(router.middleware());

Configuration

Add a description to the route config:

router.get('/', {meta: {description: 'Home page'}}, function* () {
  this.body = "Home page under construction since 2009";
});

Hide a resource by not exposing routes:

// Expose routes to documentation generator
//app.routes = router.routes;

Hide individual routes in a resource app from documentation by adding hide: true to route metadata:

// Documented route:
router.get('/', {meta: {description: 'Main route'}}, function* () {
  this.body = 'Hello world';
});

// Hidden route:
router.get('/secretRoute', {meta: {description: 'Nobody here but us chickens.', hide: true}}, function* () {
  this.body = 'This is a hidden world';
});

Add middleware to intercept requests before routing to docs:

var docs = require('koa-resourcer-docs');

// Respond with 404 if not in a development environment
docs.useRequestHandler(function* (next) {
  if (process.env.NODE_ENV === 'development') {
    return yield next;
  }
  this.throw(404);
});

For backwards compatibility "hide" and "description" on the koa-joi-router configuration object are still supported but no longer recommended since they pollute the namespace of the configuration.

Installation

npm install koa-resourcer-docs --save

Sponsored by

Pebble Technology!

LICENSE

MIT

resourcer-docs's People

Contributors

aheckmann avatar jtupiter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

isabella232

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.