The heart of a Joystick app begins in the /index.server.js file at the root of your app. In development, when you run joystick start, Joystick will run this file with node, starting the Express HTTP server under the hood and instrumenting all of Joystick’s server-side features.
By calling joystick.app() from the default export of @joystick.js/node, you can define your app server and configure its behavior.
Example Usage
/index.server.js
import joystick from '@joystick.js/node';
joystick.app({
routes: {
'/': (req = {}, res = {}) => {
res.send('Hello!');
},
},
});
In this example, we define a single GET route at /. When the app server starts, Joystick initializes the HTTP server and sets up all configured routes and features.
API
Definition
joystick.app(options: object) => Promise
Parameters
- options object required
-
An object defining configuration options for
joystick.app().- accounts object
- Configuration for Joystick’s user accounts APIs like Validating Signup Metadata and Event Hooks.
- api object
- An object representing an API schema for the app.
- caches function
- A function that contains calls to server-side caches for your app. Run automatically by Joystick on app startup.
- cluster boolean
- Turn Node.js clustering on or off for your app. If turned on, Joystick will automatically fork your app process to match the number of processors on the host machine.
- cron_jobs object
- An object containing cron job definitions for the app.
- csp object
- An object containing Content Security Policy (CSP) definitions.
- events object
- An object containing Node.js event listener methods.
- fixtures function
- A function called after databases are connected to define database fixtures.
- indexes function
- A function called after databases are connected to define database indexes.
- middleware array[function]
- An array of middleware functions for the app.
- queues object
- An object containing queue definitions for the app.
- routes object required
- An object containing route definitions for the app.
- uploaders object
- An object containing uploader definitions for the app.
- websockets object
- An object containing WebSocket server definitions.