Express HTTP Server, and Socket.IO translator for APX API server
Simply add the initializer to the Apx config.
$ npm install apx apx-express-socket.io
var apx = require('apx')
apx.start({
translators: ['apx-express-socket.io']
})
As of writing we are using Socket.IO 0.9.16
. After quite a bit of research and testing for our test
suite it wont quite shut down correctly even when the HTTP server is closed. Express shuts down just fine
but Socket.IO uses an instance upstream that doesn't seem to want to shutdown and restart within our tests.
In order to get the tests passing we restructured our tests to use a single instance of the translator rather than restarting it for each section.
In production this should not cause a limitation however we are open to suggestions on how to better handle shutting Socket.IO down. That way when the translator is stopped it can truly be started again.
express.enabled
true
Enable or disable express also listening on the port.
express.host
null
Host for express to listen on will default to the express default otherwise
express.port
3000
Port to listen on otherwise will default to 3000
express.logger
null
Enable or disable the express connection logger explicitly. By default it will
be used during development and disabled when NODE_ENV
is set to production
express.static
null
Set this to the root path of the static file server to be used with express. No static server will be setup if this variable is not set.
express.routes
Array of routes that should be accepted.
{
express: {
routes: [
{get: {path: '/status', file: 'actions/status.js'}}
{post: {path: '/page', file: 'actions/page.js', methods: ['list','find','findOne','save','remove']}}
]
}
}
Busboy is the HTTP multipart parser for the express translator. In order to configure busboy use any of the prescribed configuration options in the docs see here
Example
{
express: {
busboy: {
limits: {
fileSize: 33554432 //32MB
}
}
}
}
socket-io.enabled
true
Enable or disable Socket.IO also listening on the express port.
socket-io.config
{}
Configuration object to be passed to socket.io at call time.
socket-io.routes
Array of routes that should be accepted. These would be considered event listeners, eg page:list
{
'socket-io': {
routes: [
{status: 'actions/status.js'},
{page: {file: 'actions/page.js', methods: ['list','find','findOne','save','remove']}}
]
}
}
It is imperative to use redis to back Socket.IO in production or cluster environments. Here is an example of the configuration.
var redis = require('redis')
, RedisStore = require('socket.io/lib/stores/redis')
, IOStore = new RedisStore({
redisPub: redis.createClient(),
redisSub: redis.createClient(),
redisClient: redis.createClient()
}))
apx.start({
'socket-io': {
config: {
store: IOStore
}
}
})
busboy
to handle incoming file uploadsLanguage | javascript |
Version | 0.3.1 |
Git URL | https://github.com/nullivex/apx-express-socket.io |
License | MIT |
Description | Express HTTP Server, and Socket.IO translator for APX API server |
Keywords |