Skip to content
This repository has been archived by the owner on Jan 10, 2019. It is now read-only.

Zorium/exoid-router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published