express-middleware
An express middleware to serve and register remote dynamic components.
General
The middleware is used by @dynamico/core
and @dynamico/cli
so usually you won't have to call the routes here your self. If you still want to learn more go to the Routes section. If you just want to start using @dynamico
jump straight in to the Installation and Initialization sections.
Installation
Add the library along with the required dependencies to your server. You need to provide some storage provider. This is example uses the file system storage provider:
$ yarn add @dynamico/express-middleware
$ yarn add @dynamico/driver
$ yarn add @dynamico/fs-storage
Initialization
The middleware takes as an argument an instance of a @dynamico/driver
initialized with an object that implements the Storage
interface exported by the driver. In this example we'll use @dynamico/fs-storage
, but you should check out the other options (or implement a better one!).
Here is an example for initializing the middleware, prefixing the route with /api/components
.
const dynamicoMiddleware = require('@dynamico/express-middleware');
app.use('/api/components', dynamicoMiddleware(new FSStorage('./components')));
API
dynamicoMiddleware(storage: Storage, { readOnly }: Options = {}): AsyncRouterInstance
Arguments
- storage (required)
- An implementation of the Storage interface exported from
@dynamico/driver
. (Check out @dynamico/s3-storage
for production usage).
- Options (optional)
- readOnly: boolean? - whether or not the middleware should expose an endpoint to save a component. use this option to create a separate server.
Returns
- A middleware ready to be used by your express app.
Routes
The middleware exposes a few routes that both @dynamico/core
and @dynamico/cli
know how to use.