endo-core
Version:
Put some description here
93 lines (76 loc) • 4.83 kB
text/coffeescript
MeshbluAuth = require 'express-meshblu-auth'
_ = require 'lodash'
passport = require 'passport'
httpSignature = require '@octoblu/connect-http-signature'
CredentialsDeviceController = require './controllers/credentials-device-controller'
FormSchemaController = require './controllers/form-schema-controller'
MessagesController = require './controllers/messages-controller'
MessagesV2Controller = require './controllers/messages-v2-controller'
MessageSchemaController = require './controllers/message-schema-controller'
OctobluAuthController = require './controllers/octoblu-auth-controller'
ResponseSchemaController = require './controllers/response-schema-controller'
StaticSchemasController = require './controllers/static-schemas-controller'
UserDevicesController = require './controllers/user-devices-controller'
class Router
constructor: (options) ->
{
appOctobluHost
credentialsDeviceService
messageRouter
messagesService
serviceUrl
userDeviceManagerUrl
staticSchemasPath
} = options
throw new Error 'appOctobluHost is required' unless appOctobluHost?
throw new Error 'credentialsDeviceService is required' unless credentialsDeviceService?
throw new Error 'meshbluConfig is required' unless ?
throw new Error 'meshbluPublicKey is required' unless ?
throw new Error 'messagesService is required' unless messagesService?
throw new Error 'messageRouter is required' unless messageRouter?
throw new Error 'serviceUrl is required' unless serviceUrl?
throw new Error 'userDeviceManagerUrl is required' unless userDeviceManagerUrl?
throw new Error 'healthcheckService is required' unless ?
throw new Error 'healthcheckService.get is not a function (and must be)' unless _.isFunction .get
= new CredentialsDeviceController {credentialsDeviceService, appOctobluHost, serviceUrl, userDeviceManagerUrl}
= new FormSchemaController {messagesService}
= new MessagesController {messageRouter}
= new MessagesV2Controller {messageRouter}
= new MessageSchemaController {messagesService}
= new OctobluAuthController
= new ResponseSchemaController {messagesService}
= new StaticSchemasController {staticSchemasPath}
= new UserDevicesController
rejectIfNotServiceUuid: (req, res, next) =>
return res.sendStatus 401 unless req.get('x-meshblu-uuid') == .uuid
next()
route: (app) =>
meshbluAuth = new MeshbluAuth
app.get '/', (req, res) => res.redirect('/auth/octoblu')
app.get '/v1/form-schema', .list
app.get '/v1/message-schema', .list
app.get '/v1/response-schema', .list
app.get '/schemas/:name', .get
app.get '/proofoflife', .get
app.get '/auth/octoblu', passport.authenticate('octoblu')
app.get '/auth/octoblu/callback', passport.authenticate('octoblu', failureRedirect: '/auth/octoblu'), .storeAuthAndRedirect
app.post '/v2/messages', httpSignature.verify(pub: ), httpSignature.gateway(), , .create
app.use meshbluAuth.auth()
app.use meshbluAuth.gatewayRedirect('/auth/octoblu')
upsert = .upsertWithRedirect
upsert = .upsertWithoutRedirect if
app.get '/auth/api', passport.authenticate('api')
app.get '/auth/api/callback', passport.authenticate('api'), upsert
app.post '/auth/api/callback', passport.authenticate('api'), upsert
app.post '/v1/messages', .create
app.all '/credentials/:credentialsDeviceUuid*', .getCredentialsDevice
app.get '/credentials/:credentialsDeviceUuid', .get
app.get '/credentials/:credentialsDeviceUuid/user-devices', .list
app.post '/credentials/:credentialsDeviceUuid/user-devices', .create
app.delete '/credentials/:credentialsDeviceUuid/user-devices/:userDeviceUuid', .delete
app.use (req, res) => res.redirect '/auth/api'
module.exports = Router