exoid-router
Router for Exoid protocol
Last updated 3 years ago by zolmeister .
MIT · Original npm · Tarball · package.json
$ cnpm install exoid-router 
SYNC missed versions from official npm registry.

Exoid Router

Create Exoid compatible APIs

router = require 'exoid-router'

authed = (handler) ->
  unless handler?
    return null

  (body, req, rest...) ->
    unless req.isAuthed
      router.throw status: 401, message: 'Unauthorized'

    handler body, req, rest...

routes = router
# Public Routes
.on 'auth.login', AuthCtrl.login

# Authed Routes
.on 'users.getMe', authed UserCtrl.getMe

# As Express Middleware
app.post '/exoid', routes.asMiddleware()

# Joi schema validation
Joi = require 'joi'
# validate {presence: 'required', convert: false}
router.assert('str', Joi.string())

# manual throw, error sent to client
router.throw message: 'invalid api call'

routes.resolve path, body, req
.then ({result, error, cache}) -> null

Current Tags

  • 0.3.0                                ...           latest (3 years ago)

9 Versions

  • 0.3.0                                ...           3 years ago
  • 0.2.6                                ...           4 years ago
  • 0.2.5                                ...           4 years ago
  • 0.2.4                                ...           4 years ago
  • 0.2.3                                ...           4 years ago
  • 0.2.2                                ...           5 years ago
  • 0.2.1                                ...           5 years ago
  • 0.2.0                                ...           5 years ago
  • 0.1.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dependencies (4)
Dev Dependencies (4)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |