Stratumn agent for NodeJS [ALPHA - incompatible with production]
This NodeJS module exposes functions to create Stratumn agents using Javascript.
Creating an HTTP server for an agent
var express = require('express');
var Agent = require('stratumn-agent');
var actions = require('./lib/actions');
var storeHttpClient = Agent.storeHttpClient(process.env.STRATUMN_STORE_URL || 'http://store:5000');
var fossilizerHttpClient = Agent.fossilizerHttpClient(process.env.STRATUMN_FOSSILIZER_URL || 'http://fossilizer:6000');
var agent = Agent.create(actions, storeHttpClient, fossilizerHttpClient, {
agentUrl: 'http://localhost:3000',
salt: process.env.STRATUMN_SALT || Math.random()
});
var agentHttpServer = Agent.httpServer(agent, { cors: {} });
var app = express();
app.disable('x-powered-by');
app.use('/', agentHttpServer);
app.listen(3000, function() {
console.log('Listening on :' + this.address().port);
});
Advanced usage
create
creates an agent instance.storeHttpClient
creates an instance to work with stores via HTTP.fossilizerHttpClient
creates an instance to work with fossilizers via HTTP.httpServer
creates an HTTP server for an agent.