Skip to content

Satellite

TD edited this page Jan 16, 2023 · 12 revisions

Overview

Satellite is a Microservice Framework utilized by the Telescope project that helps creates an Express server, with many components preconfigured. Furthermore, Satellite has built-in support for node modules such as cors and Helmet, with default settings, eliminating the need for manual installation and configuration.

Table of Contents

About Microservices

Microservices is an approach to developing software in such a manner that it is composed of small independent services that communicate with an API. Telescope is an example of software using microservices. The projects we work on in other WEB courses utilize monolithic architectures, as all the processes are tightly coupled and run as a single service. Microservices architecture is easy to scale, deploy, and update.

Installation and Configuration

Satellite can be installed as a dependency in a Nodejs project using the following npm command:

npm install --save @senecacdot/satellite

To use Satellite, the following JWT verification-specific environment variables need to be configured:

Variable Description
JWT_SECRET the secret used for JWT token verification
JWT_AUDIENCE the audience (aud) claim expected in JWT token verification
JWT_ISSUER the issuer (iss) claim expected in JWT token verification

Basic Usage

// index.js

// import the Satellite constructor and preconfigured logger
const { Satellite, logger } = require('@senecacdot/satellite');

// defining the microservice
const service = new Satellite();

const HTTP_PORT = process.env.PORT || 8000;

// adding a route
service.router.get('/', (req, res) => {
    res.json({ message: 'Hello from Home route'});
});

// run service on the specified port:
service.start(HTTP_PORT, () => {
    logger.info(`Satellite microservice running on port: ${HTTP_PORT}`);
});

Output

terminal output browser output

Express vs. Satellite

Express is a Nodejs framework used to develop the backend of a web application. Being a Nodejs framework means Express is a customized version of Nodejs with preconfigured components to speed up development. On the other hand, Satellite is a microservice framework, running Express under the hood to create a server with many settings enabled, requiring minimal configuration from the developers.

Key Features

  • Satellite offers built-in support for cors and helmet, turned on by default
  • Optional hooks such as beforeParsers and beforeRouter that grant access to the app object during creation but prior to adding the hooks
  • Ability to specify optional router in stead of default one created automatically by Satellite
  • Ability to specify an optional credentials object with key and cert values without having to require https
  • middleware functions such as isAuthenticated and isAuthorized to help with routes
  • logger based on Pino to output log messages with context
  • hash function, which returns a 10-character-long hash for the value provided
  • createServiceToken function that generates a short-lived access token with the "service" role
  • createError function that generates unique HTTP Error object using the http-errors library
  • Ability to create instance an of ElasticSearch using the Elastic() constructor
  • fetch function which accepts url and options as arguments to initiate an HTTP request to an endpoint, using node-fetch.

Sources: