Actionhero is a realtime multi-transport nodejs API Server with integrated cluster capabilities and delayed tasks
APACHE-2.0 License
Routes
action=theAction
or hitting the named URL for an action /api/theAction
will always override RESTful routingconnection.userId = 123
General
Bugs
Windows
Using the unstable readline
module, catching of sigint
on windows can be achieved. This allows for a graceful shutdown.
Published by evantahler over 11 years ago
Action PreProcessor
You can overwrite the stub method api.actionProcessor.prototype.preProcessAction
which will be called before every action. You can use this to do things like authentication before allowing a connection into an action. The arguments to preProcessAction
are:
function(api, connection, actionTemplate, callback)
.
actionTemplate
is the literal action definition, so you can inspect actionTemplate.name
, actionTemplate.description
, etc. You can feel free to add additional parameters to your action definitions like actionTemplate.secure
which you can inspect in the preProcessAction
method.
The goal of preProcessAction
is to return either true
or false
to the callback, where true
will move on to the action proper, and false
will render the connection types default return to the client. It would be best to set connection.error
if you are returning false to preProcessAction
's callback so the client has an idea of why they were denied.
It is best to define preProcessAction
in an initializer.
Server
All of the server types (web, webSocket, socket) are now extended from a prototypical genericServer
class. This should make it easer to make your own servers going forward
Chat
Bugs
General
actionHero generateTask
, you no longer are required to pass description (name will be used if you don't)actionHero generateAction
, you no longer are required to pass description (name will be used if you don't)api.configData.general.id
. Be careful to make this unique for all of your servers!Published by evantahler over 11 years ago
Modular & Prototypical Servers
if type == 'web'
shenanigansconfig.js
chnges. Please see the example for updatespipe
generateServer
, exists to help you make serversweb server
connection.rawConnection.responseHeaders
from connection.responseHeaders
connection.rawConnection.responseHttpCode
from connection.responseHttpCode
socket server
websocket server
other
config.js
drastically simplified (no more commonWeb
, servers block, etc)API Versions
ActionHero can now support multiple versions of the same action. This will allow you to support actions/routes of the same name with upgraded functionality.
action.version
attribute
action.version
, they will be defaulted to version 1.apiVersion
has been introduced. This is used to directly specify the version of an action a client may requestapiVersion
, they will be directed to the higest numerical versionexports.routes = {
all: [
// creates routes like `/api/myAction/1/` and `/api/myAction/2/`
// will also default `/api/myAction` to the latest version
{ path: "/myAction/:apiVersion", action: "myAction" },
// creates routes like `/api/1/myAction/` and `/api/2/myAction/`
// will also default `/api/myAction` to the latest version
{ path: "/:apiVersion/myAction", action: "myAction" },
]
};
middleware
This replaces api.actionProcessor.prototype.preProcessAction
actionHero provides hooks for you to execute custom code both before and after the excecution of all actions. You do this by adding to the api.actions.preProcessors
and api.actions.postProcessors
array. Functions you add here will be excecuted in order on the connection.
This is a great place to write atutentication logic or custom loggers.
preProcessors, like actions themselves, return the connection and a toProcess
flag. Setting toProcess
to false will block the excecution of an action. You can operate on connection.response
and connection.error
, just like within an action to create messages to the client.
preProcessors are provided with connection
, actionTemplate
, and next
. They are expected to return (connection, toProcess)
postProcessors are provided with connection
, actionTemplate
, and next
. They are expected to return (connection)
bugs
Published by evantahler over 11 years ago
actionHero run
This version introduces the ability to run actionHero's methods from the command line. This is similar to Ruby's rake
command. the new actionHero run
command has the api object in scope.
For example,
actionHero run --method="api.cache.save" --args=test,123
actionHero run --method="api.cache.load" --args=test
> ./node_modules/.bin/actionHero run --method="api.cache.save" --args=test,123
info: actionHero >> run
info: project_root >> /Users/evantahler/PROJECTS/actionHero/
info: actionHero_root >> /Users/evantahler/PROJECTS/actionHero/
{ '0': null, '1': true }
> ./node_modules/.bin/actionHero run --method="api.cache.load" --args=test
info: actionHero >> run
info: project_root >> /Users/evantahler/PROJECTS/actionHero/
info: actionHero_root >> /Users/evantahler/PROJECTS/actionHero/
{ '0': null,
'1': '123',
'2': null,
'3': 1373154368728,
'4': 1373154385785 }
The response of the run
command will be an ordered list of all the arguments passed to the callback (if it has one), or the function's return value (if the method is synchronous).
For safety, you can not run arbitrary code from actionHero run
, so you will need to define first define the method you wish to call in an initializer, and append it to the api
object
Run actionHero help
for more information.
This version also formally separates actionHero.start
into actionHero.initialize
(loads your initializers) and actionHero.start
(runs the _start
methods and starts the various servers). Don't worry, you can still call actionHero.start
without actionHero.initialize
(it will run initialize
for you).