How to use the actionhero.api.actions function in actionhero

To help you get started, we’ve selected a few actionhero examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github actionhero / actionhero-angular-bootstrap-cors-csrf / initializers / session.js View on Github external
const sessionData = await api.session.load(data.connection)
            if (!sessionData) { throw new Error('Please log in to continue') }
            if (
              (data.action.indexOf('resque') < 0) &&
              (!data.params.csrfToken || data.params.csrfToken !== sessionData.csrfToken)
            ) { throw new Error('CSRF error') }

            data.session = sessionData
            const key = api.session.prefix + data.connection.fingerprint
            await redis.expire(key, api.session.ttl)
          }
        }
      }
    }

    api.actions.addMiddleware(api.session.middleware['logged-in-session'])
    api.params.globalSafeParams.push('csrfToken')
  }
}
github actionhero / actionhero-tutorial / initializers / middleware.js View on Github external
async initialize () {
    const middleware = {
      name: this.name,
      global: true,
      preProcessor: async ({ actionTemplate, params }) => {
        if (actionTemplate.authenticated === true) {
          const match = await api.users.authenticate(params.userName, params.password)
          if (!match) { throw Error('Authentication Failed.  userName and password required') }
        }
      }
    }

    api.actions.addMiddleware(middleware)
  }
github actionhero / ah-resque-ui / initializers / ah-resque-ui.js View on Github external
}
        }
      }

      middleware['ah-resque-ui-proxy-middleware'].postProcessor = async (data) => {
        for (const i in api.config['ah-resque-ui'].middleware) {
          const middlewareName = api.config['ah-resque-ui'].middleware[i]
          const middleware = api.actions.middleware[middlewareName]
          if (typeof middleware.postProcessor === 'function') {
            await middleware.postProcessor(data)
          }
        }
      }
    }

    api.actions.addMiddleware(middleware['ah-resque-ui-proxy-middleware'])
  }
}