@akeraio/web v1.1.5
Web Handler Middleware for Akera Application Server.
This will serve as a proxy to one or more akera.io application server(s) by passing all incomming web requests to be handled by the corresponding broker and pipe the response back to the client.
As opposed to the @akeraio/rest that can directly run any standard
procedures by passing input/output parameters, this can only execute special 'handlers' -
either the 'classical' WebSpeed wrap-cgi procedures (includes wrap-cgi.i) or the new
WebHandler objects (implements OpenEdge.Web.WebHandler).
Installation
$ npm install @akeraio/webDocs
- Website
- Documentation, also available in
docfolder.
API
var akeraWeb = require('@akeraio/web')The akeraWeb object exposes the middleware (the default function if Typescript is used)
factory that can be used to create an Express middleware.
akeraWeb.middleware(configuration)
Returns an akera.io Web Handler middleware that can be used on an Express application.
config: ConnectionPoolOptions | ConnectionPool
Can be one or an array of broker configuration for remote akera.io brokers. If one configuration is used then all requests on the middleware router will be dispatched directly to that broker.
When multiple configurations are used then for each unique broker a
sub-route is added to the router using the broker's alias as route
and each request on the middleware requires one route parameter - the
broker alias, based on which the request is dispatched to the
corresponding broker.
If all configurations have the same alias - fail-over configuration,
then the broker will be mounted on the router's root as if a single
configuration is provided.
ConnectionPool(configuration)
When both Web Handler and other Rest interfaces are to be installed
for the same akera.io broker(s) then one ConnectionPool instance
can be shared among them in order to use the same connections pool
to the akera.io application server.
The mount method can be used on the AkeraWeb instance to retrieve
the middleware router.
Errors
Broker name missing
When multiple brokers are defined each request must have one route parameter that represents the broker name (alias) to dispatch the request to.
Broker not found
When multiple brokers are defined if the broker name sent as route parameter in request is not present in configuration.
Unable to connect/All servers offline
When no connection can be established to any of the defined application server(s) for the broker.
File not found
When the requested Web Handler is not found on the akera.io application server.
Examples
Mount a single akera.io broker
A 'failsafe' configuration is defined using two akera.io application
servers running on different ports on the same computer as the Express
web server (localhost).
All requests sent on /web path will be handled by the Web Handler
middleware and will be dispatched to the first broker to which a
connection can be established.
import * as express from 'express';
import { middleware, ConnectionPoolOptions } from '@akeraio/web';
let app: express.Application = express();
let connectionOptions: ConnectionPoolOptions = {
"config": [ { "name": "demo1",
"host": "localhost",
"port": 8900 },
{ "name": "demo2",
"host": "localhost",
"port": 9900 }
]
};
app.use('/web', middleware(connectionOptions));A request made on /web/demo/sports2000/getCustomers will run the
Web Handler demo/sports2000/getCustomers on the akera.io
application server.
Mount multiple akera.io brokers
A configuration is defined using two separate akera.io application
servers running on different ports on the same computer as the Express
web server (localhost).
All requests sent on /web path will be handled by the Web Handler
middleware and will be dispatched to the corresponding broker based
on the broker alias (first route parameter).
import * as express from 'express';
import {AkeraWeb, ConnectionPool} from '@akeraio/web';
let app: express.Application = express();
let connectionPool: ConnectionPool = new ConnectionPool({
"config": [ { "name": "demo1",
"host": "localhost",
"port": 8900 },
{ "name": "demo2",
"host": "localhost",
"port": 9900 }
]
});
let akeraWeb = new AkeraWeb();
app.use('/web', akeraWeb.mount(connectionPool));A request made on /web/demo1/demo/sports2000/getCustomers will run
the Web Handler demo/sports2000/getCustomers on the demo1 broker
while requests made on /web/demo2/ will be dispacthed to the demo2
broker. Multiple akera.io application servers can be configured for
each 'broker' - using the same alias, for failover setup.
License
Copyright (c) 2015 ACORN IT, Romania - All rights reserved
This Software is protected by copyright law and international treaties. This Software is licensed
(not sold), and its use is subject to a valid WRITTEN AND SIGNED License Agreement. The unauthorized
use, copying or distribution of this Software may result in severe criminal or civil penalties, and
will be prosecuted to the maximum extent allowed by law. 