0.3.0 • Published 7 years ago

exoid-router v0.3.0

Weekly downloads
-
License
MIT
Repository
-
Last release
7 years ago

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
0.3.0

7 years ago

0.2.6

7 years ago

0.2.5

8 years ago

0.2.4

8 years ago

0.2.3

8 years ago

0.2.2

9 years ago

0.2.1

9 years ago

0.2.0

9 years ago

0.1.0

9 years ago