@joystick.js/node

Basic Route Definitions

How to define basic routes in joystick.app() using the routes option.

When you start your app with joystick.app(), Joystick starts an HTTP server via Express in the background and registers any routes you define on the routes object passed via the options object to joystick.app().

By default, when you specify a route, Joystick defines an HTTP GET route (meaning the route can only receive HTTP requests made with the GET method), mapped to the URL you specify.

Example Usage

/index.server.js

import joystick from '@joystick.js/node';

joystick.app({
  routes: {
    '/': (req = {}, res = {}) => {
      return res.status(200).send('Howdy');
    },
  },
});

In the example above, we define a simple "index" route at / in our app using the basic route syntax: a key containing the path for our route, assigned a route handler as a callback function.

Apart from Joystick adding a few additional properties to the req and res objects, the route behaves identically to one you'd define in a vanilla Express app.

API

Definition

{
  [route_path: string]: (req: object, res: object) => void
}

Parameters

route_path function required
The callback function for the route. Receives the inbound req and res objects.