-
Notifications
You must be signed in to change notification settings - Fork 2
Server API
Create a new zygo-server instance by passing it the path to your zygo.json config file, and then initialising it. Note that the zygo.initialise() function returns a promise, resolving when it is finished.
import Zygo from 'zygo-server';
let zygo = new Zygo('zygo.json');
zygo.initialise()
.then( ... );After initialisation, the following methods are exposed by the zygo-server instance:
-
zygo.createServer()
Creates and returns a promise resolving to a simple http server listening onconfig.portif it is defined, else port 8080. Handlers can be added to the server viaserver.use(function (req, res, next, zygo) { ... })in the express style, with an added parameter to access the current zygo instance. These handlers are guaranteed to run before zygo does static file serving or routing. -
zygo.bundle()Bundles your app into thebuildDirspecified in thezygo.json. Note that bundles are only pushed to the client if the environment is set toproduction. -
zygo.unbundle()Removes all bundle config and bundles, cleaning yourbuildDir. -
zygo.route('route/path', headers, requestMethod)
Matches the given path against the routes specified in theroutes.js. If there is no match, the router falls back to thedefaultroute. The matched route's handlers are then run and the resolved component rendered onto theconfig.templateif it was specified, else a default standard template. The function resolves to the rendered html. -
zygo.setDebug([mode = true])
Sets debug mode, turning detailed error messages on and off.