Manual Reference Source Test
import HttpServer from 'pop-api/src/middleware/HttpServer.js'
public class | source

HttpServer

Class for starting the API.

Test:

Constructor Summary

Public Constructor
public

constructor(PopApi: PopApi, options: Object)

Create a new Server object.

Member Summary

Public Members
public

the http server object.

public

The port on which the API will run on.

public

The amount of workers on the cluster.

Method Summary

Public Methods
public

closeApi(database: Database, done: Function): undefined

Method to stop the API from running.

public

For the workers.

public

Method to setup the cron job.

public

Handle the errors for workers.

Public Constructors

public constructor(PopApi: PopApi, options: Object) source

Create a new Server object.

Params:

NameTypeAttributeDescription
PopApi PopApi
  • nullable: false

The PopApi instance to bind the server to.

options Object
  • nullable: false

The options for the server.

options.app Express
  • nullable: false

The application instance to create a server for.

options.serverPort number
  • optional
  • default: process.env.PORT
  • nullable: false

The port the API will run on.

options.workers number
  • optional
  • default: 2
  • nullable: false

The amount of workers to fork.

Throw:

TypeError

'app' is a required option for the HttpServer middleware!

Test:

Public Members

public serverPort: number source

The port on which the API will run on. Default is 5000.

public workers: number source

The amount of workers on the cluster.

Public Methods

public closeApi(database: Database, done: Function): undefined source

Method to stop the API from running.

Params:

NameTypeAttributeDescription
database Database
  • nullable: false

The database connection to close.

done Function
  • optional
  • nullable: true

Function to exit the API.

Return:

undefined

Test:

public forkWorkers(): undefined source

For the workers.

Return:

undefined

Test:

public setupApi(app: Express): undefined source

Method to setup the cron job.

Params:

NameTypeAttributeDescription
app Express
  • nullable: false

The application instance to create a server for.

Return:

undefined

Test:

public workersOnExit(): undefined source

Handle the errors for workers.

Return:

undefined

Test: