seneca-web-adapter-express.js
function handleRoute(seneca, options, request, reply, route, next) {
  if (options.parseBody) {
    return ReadBody(request, finish)
  }
  finish(null, request.body || {})

  // Express requires a body parser to work in production
  // This util creates a body obj without neededing a parser
  // but doesn't impact loading one in.
  function finish(err, body) {
    if (err) {
      return next(err)
    }

    // This is what the seneca handler will get
    // Note! request$ and response$ will be stripped
    // if the message is sent over transport.
    const payload = {
      request$: request,
      response$: reply,
      args: {
        body: body,
        route: route,
        params: request.params,
        query: request.query,
        user: request.user || null
      }
    }

    // Call the seneca action specified in the config
    seneca.act(route.pattern, payload, (err, response) => {
      if (err) {
        return next(err)
      }

      // Redirect or reply depending on config.
      if (route.redirect) {
        return reply.redirect(route.redirect)
      }
      if (route.autoreply) {
        return reply.send(response)
      }
    })
  }
}
function handleRoute(seneca, options, request, reply, route, next) {
  if (options.parseBody) {
    return ReadBody(request, finish)
  }
  finish(null, request.body || {})

  // Express requires a body parser to work in production
  // This util creates a body obj without neededing a parser
  // but doesn't impact loading one in.
  function finish(err, body) {
    if (err) {
      return next(err)
    }

    // This is what the seneca handler will get
    // Note! request$ and response$ will be stripped
    // if the message is sent over transport.
    const payload = {
      request$: request,
      response$: reply,
      args: {
        body: body,
        route: route,
        params: request.params,
        query: request.query,
        user: request.user || null
      }
    }

    // Call the seneca action specified in the config
    seneca.act(route.pattern, payload, (err, response) => {
      if (err) {
        return next(err)
      }

      // Redirect or reply depending on config.
      if (route.redirect) {
        return reply.redirect(route.redirect)
      }
      if (route.autoreply) {
        return reply.send(response)
      }
    })
  }
}
function handleRoute ( seneca , options , request , reply , route , next ) { if ( options . parseBody ) { return ReadBody ( request , finish ) } finish ( null , request . body || { } ) // Express requires a body parser to work in production // This util creates a body obj without neededing a parser // but doesn't impact loading one in. function finish ( err , body ) { if ( err ) { return next ( err ) } // This is what the seneca handler will get // Note! request$ and response$ will be stripped // if the message is sent over transport. const payload = { request$ : request , response$ : reply , args : { body : body , route : route , params : request . params , query : request . query , user : request . user || null } } // Call the seneca action specified in the config seneca . act ( route . pattern , payload , ( err , response ) => { if ( err ) { return next ( err ) } // Redirect or reply depending on config. if ( route . redirect ) { return reply . redirect ( route . redirect ) } if ( route . autoreply ) { return reply . send ( response ) } } ) } }
All routes ultimately get handled by this handler if they have not already be redirected or responded.
All routes ultimately get handled by this handler if they have not already be redirected or responded .