Giter Club home page Giter Club logo

lucca's Introduction

Lucca

Lucca's artwork

Lucca is a lightweight Express-style router for Koa (v1). It is named after the character Lucca from Chrono Trigger. Quickly coded for gasch as I had problems with both koa-router and impress-router

Use

var app = require("koa")(),
    router = require("lucca")("main");

router.use(function*(next) {
  console.log("middle...");
  yield next;
  console.log("...ware!");
});

router.get("/", function*() {
  this.response.body = "Hello world!";
});

// Nested router
var child = require("lucca")("child");
child.get("/", function*() {});
child.post("/operation", require("authMiddleware")(), function*() {
  // stuff...
});

router.use("/child", child);

app.use(router);
app.listen(3000);

Documentation

lucca([name]) => Router

Returns a router.

Parameter Type Description
[name] String Default is anon. Used by the debug output.

Router

Routers are generator functions; they can be directly plugged into a Koa application.

router.get|post|put|delete|…(route, …mw)

Adds a middleware to the router which will call the following middleware stack only if the request method and path match the given route and HTTP verb.

Parameter Type Description
route String A path-to-regexp route.
…mw Generator function(s) A stack of middleware to be called if the route matches.

router.use(…mw)

Adds one or multiple middlewares to the router.

Parameter Type Description
…mw Generator function(s) A stack of middleware to be called if the route matches.

router.use(prefix, …mw)

Mounts a middleware stack on a given path, the mount point. Every request matching the route will be handled by the given stack before the next middleware in the router stack.

Routers can be nested without taking into account the parent routes (like in Express): The prefix is removed from Koa's context.path for the given stack and restored for the router's following middlewares.

Parameter Type Description
prefix String A path-to-regexp route. All its descendants will be matched.
…mw Generator function(s) A stack of middleware to be called if the route matches.

lucca's People

Contributors

sepsten avatar

Watchers

 avatar

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.