canvas-sketch-render-service
A HyperSource service based on HyperDrive that converts a Canvas Sketch project into production bundle delivered back to you in a HyperDrive archive.
Installation
$ npm install canvas-sketch-render-service
or (see usage)
$ npx canvas-sketch-render-service [options]
Usage
canvas-sketch-render-service can be used in various ways. The
service can be started by running the canvas-sketch-render-service
command with a few arguments or by using the module directly to create
and run your own server.
Command Line
usage: canvas-sketch-render-service [-hDV] [options]
where options can be:
-r, --registry <path> Path to HyperDrive registry
-d, --data <path> Path to where temporary data cache
-p, --port <port> Server port to listen on
-H, --host <host> Server host to listen on
-D, --debug Enable debug output
-h, --help Show this message
-V, --version Show program version
Start a server running on port 3000
by running:
$ canvas-sketch-render-service --port 3000
By default the command line program will create and access a registry at
./canvas-sketch-registry
if one is not supplied. The path should point
to a HyperDrive instance
where the key
and secret_key
files are accessible. If you need to
supply your own registry where the keys are not living along the SLEEP
files, then you will need to consume the module.
Set the path to a HyperDrive instance
$ canvas-sketch-render-service --port 3000 --registry dataUsing registry at /home/werle/repos/canvas-sketch-render-service/dataUsing TMPDIR at /tmpCanvasSketch render server listening on ws://127.0.0.1:3000
Module
The server can be started programmatically by using the module code directly.
const createServer = const hyperdrive = const ram = const registry = const server = server
API
server = createServer(opts)
Create a new canvas-sketch-render-service
server where opts
can be
registry: Object // A HyperDrive instance that will be the registry server: Object // An optional HTTP server for the WebSocket server tmpdir: String // Path to a temporary data cache directory
Client API
Users can submit a new sketch to be built by opening up a WebSocket to
/:key
where :key
is a hex encoded 64 character long string that
represents the public key of the HyperDrive archive that contains the
assets.
const key = drivekeyconst socket = `ws://your-domain.com/`
The socket connection should be a pure hypercore-protocol replication stream. The client should replicate the HyperDrive archive associated with the public key in the URI.
stream
The 'handshake'
event indicates that the service has established a
channel and provides a response key to read output from the service. The
client should replicate the response archive from the server. This has
the final built sketch!
stream
The server should send the built asset to the response archive. The
client can listen for the 'update'
event which should indicate the
server has sent the built sketch.
response
Example
Below is a simple example of an in memory registry and
canvas-sketch-render-service
server.
Server
const createServer = const hyperdrive = const ram = const registry = const server = registry server
Client
The client example bundles a sketch and sends it to the server. The response is then written to disk.
const hyperdrive = const WebSocket = const mkdirp = const pify = const pump = const ram = const fs = const bundle = bundle
Browser Preview
The canvas-sketch-render-service
server also runs
hyperdrive-http
middleware over the supplied registry. All submissions are stored in the
registry indexed by their public key.
Below is an example of an archive made available over HTTP:
http://localhost:3000/a9143642ef9afeb7b414af89a183f779c520417f006ef5f623d42040bb3ceeda
License
MIT