Skip to content

tello2004/skimo

Repository files navigation

skimo 🍵

skimo is a cozy little web router steeped in CoffeeScript, brewed on a rainy afternoon, and probably left unattended for just a little too long. Built exclusively for Koa, but you can trick 'em and pretend if you're not using it.

a taste of it

import Koa from 'koa'
import Router from 'skimo'
import { NotFound } from 'http-errors'

{ use, listen } = new Koa

users = [name: '[redacted]']

class Greeter extends Router
  constructor: -> do super

  '/': (ctx) ->
    ctx.body = "Hello, #{ctx.query?.name ? 'world'}!"

  '/:id': (ctx, match) ->
    try user = users[match.pathname.groups['id']]
    throw new NotFound unless user?

    ctx.body = "Hello, #{user.name}!"

use new Greeter().matcher
listen process.env.PORT, process.env.HOST

Documentation

class Router

constructor(@prefix = '')

populates all methods that start with a forward slash (/) into a @routes array with the format [URLPattern, function (ctx, match)]. This array is an internal property that shouldn't be modified by consumers of this library. The pattern will be prefixed with the provided @prefix.

a route is defined as a method that starts with a forward slash. This method takes two parameters:

about

named after the only coffee shop in my hometown, which is named after a Mexican Nickelodeon hit TV show.

it was extracted from my current job at Caja Popular Inmaculada Concepción, actively used in internal applications. Probably not a good choice for your own needs, though...

missed routes and errors are handled by Koa. Look for some documentation online on how to customize these. Personally, I like to just return plain HTTP errors and let the browser render the error message nicely, for brutalism.

About

lightly-caffeinated router

Topics

Resources

License

Stars

Watchers

Forks