Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

autohost

Package Overview
Dependencies
Maintainers
2
Versions
110
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

autohost

Resource-driven http server

  • 0.0.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.9K
increased by6045.16%
Maintainers
2
Weekly downloads
 
Created
Source

autohost

Features

  • Resource-based: define protocol-agnostic resources that interact via HTTP or WebSockets
  • Auto-reload resource on file change
  • WebSocket support (no fallback to other protocols)

Quick Start

var host = require( 'autohost' )();
host.init();

Configuration

Configuration can be provided optionally to the init call or during instantiation after the require. The object literal follows the format:

{
	processes: 1, // # of processes to spawn - not currently in use
	static: './public', // where to host static resources from, default value shown
	resources: './resources', // where to load resource modules from, default value shown
	port: 8800, // what port to host at, default shown
	allowedOrigin: 'leankit.com', // used to filter incoming web socket connections based on origin
	websockets: true // enables websockets
}

Resources

Resources are expected to be simple modules that return a parameterless function resulting in a JS literal that follows the format:

	{
		name: 'resource-name',
		actions: [ 
			{
				alias: 'send', // not presently utilized
				verb: 'get', // http verb
				topic: 'send', // topic segment appended the resource name
				path: '', // url pattern appended to the resource name
				resources: '', // relative path to static assets for this resource
				handle: function( envelope ) {
					// envelope.data, envelope.headers and envelope.params may contain
					// information about the request/message received

					// envelope reply takes a object literal with data property for
					// http body|websocket message					
				}
			}
		]
	}

API

Lots of methods are available but not generally intended for use outside the library. Other than init, there are two methods for interacting with connected websocket clients.

  • sendToClient( id, topic, message ) - sends message to specific client via websocket (returns true if successful)
  • notifyClients( topic, message ) - sends message to all clients via web sockets

Events

  • 'socket.client.connected', { socket: socketConnection } - raised when a client connects
  • 'socket.client.identified', { socket: socketConnection, id: id } - raised when client reports unique id

TO DO

  • Add support for clustering (multiple listening processes)
  • Add support for basic auth / token auth / custom auth
  • Add support for rate limiting
  • Better logging
  • More thorough error handling
  • Support either Socket.IO or WebSockets via config

FAQs

Package last updated on 16 Mar 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc