Server

new Server()

Server class

Since
  • 1.0.0
Author
  • Glenn de Haan
Example
const {Runtime, Server} = require('@neobeach/core');
const Api = require('./routers/Api');

const server = new Server();

Runtime(() => {
    server.includeDefaultBodyParsers();
    server.loadRouters([Api]);
    server.run();
});

Methods

includeDefaultBodyParsers()

Includes/loads default express body parsers (json, text, urlencoded and multer) with recommended config into the Express app

Since
  • 1.0.0
Author
  • Glenn de Haan
Example
const {Runtime, Server} = require('@neobeach/core');

const server = new Server();

Runtime(() => {
    server.includeDefaultBodyParsers();
    server.run();
});

includeDefaultCompression()

Includes/loads default compression (deflate, gzip) with recommended config into the Express app

Since
  • 1.0.0
Author
  • Glenn de Haan
Example
const {Runtime, Server} = require('@neobeach/core');

const server = new Server();

Runtime(() => {
    server.includeDefaultCompression();
    server.run();
});

includeDefaultCookieParser()

Includes/loads cookie parser with recommended config into the Express app

Since
  • 2.1.0
Author
  • Glenn de Haan
Example
const {Runtime, Server} = require('@neobeach/core');

const server = new Server();

Runtime(() => {
    server.includeDefaultCookieParser();
    server.run();
});

includeDefaultCorsHeaders(origin)

Includes/loads default CORS headers with recommended config into the Express app

Parameters:
NameTypeDescription
originString

String with allowed origin URL's

Since
  • 1.0.0
Author
  • Glenn de Haan
Example
const {Runtime, Server} = require('@neobeach/core');

const server = new Server();

Runtime(() => {
    server.includeDefaultCorsHeaders();
    server.run();
});

includeDefaultSecurityHeaders()

Includes/loads default security headers with recommended config into the Express app

Since
  • 1.0.0
Author
  • Glenn de Haan
Example
const {Runtime, Server} = require('@neobeach/core');

const server = new Server();

Runtime(() => {
    server.includeDefaultSecurityHeaders();
    server.run();
});

loadMiddlewares(middlewares)

Load global middlewares into the Express app

Parameters:
NameTypeDescription
middlewaresarray.<function(*, *, *)>

An array with Express middleware functions

Since
  • 1.0.0
Author
  • Glenn de Haan
Example
const {Runtime, Server} = require('@neobeach/core');

const server = new Server();

Runtime(() => {
   server.loadMiddlewares([
       (req, res, next) => {
           // Execute custom code here
           next();
       }
   ]);
   server.run();
});

loadRemixFramework(serverBuild)

Attach a Remix Framework build to our Express server

Parameters:
NameTypeDescription
serverBuild*

A Remix Server build

Since
  • 1.0.0
Author
  • Glenn de Haan
Example
import * as serverBuild from "@remix-run/dev/server-build";

const {Runtime, Server} = require('@neobeach/core');

const server = new Server();

Runtime(() => {
    server.loadRemixFramework(serverBuild);
    server.run();
});

loadRouters(routers)

Load routers into the Express app

Parameters:
NameTypeDescription
routersarray

An array with Routers

Since
  • 1.0.0
Author
  • Glenn de Haan
Example
const {Runtime, Server} = require('@neobeach/core');
const Api = require('./routers/Api');

const server = new Server();

Runtime(() => {
    server.loadRouters([Api]);
    server.run();
});

loadStatic(directory, prefixopt)

Serves a static directory from the Express app

Parameters:
NameTypeAttributesDefaultDescription
directorystring

Local directory path where the static files live

prefixstring<optional>
/

Optional prefix to create a virtual path

Since
  • 1.0.0
Author
  • Glenn de Haan
Example
const {Runtime, Server} = require('@neobeach/core');

const server = new Server();

Runtime(() => {
    server.loadStatic('public');
    server.run();
});

run() → {function}

Starts the Express server

Since
  • 1.0.0
Author
  • Glenn de Haan
Returns:
Type: 
function
Example
const {Runtime, Server} = require('@neobeach/core');
const Api = require('./routers/Api');

const server = new Server();

Runtime(() => {
    server.run();
});

setEJSViewEngine(views)

Sets the Express render engine to EJS

Parameters:
NameTypeDescription
viewsstring

Path to the EJS views directory

Since
  • 2.1.0
Author
  • Glenn de Haan
Example
const {Runtime, Server} = require('@neobeach/core');

const server = new Server();

Runtime(() => {
    server.setEJSViewEngine(`${__dirname}/views`);
    server.run();
});

setParameter(name, value)

Sets an Express app parameter

Parameters:
NameTypeDescription
namestring

An express parameter name

value*

You specified value for the parameter

Since
  • 1.0.0
Author
  • Glenn de Haan
Example
const {Runtime, Server} = require('@neobeach/core');

const server = new Server();

Runtime(() => {
    server.setParameter('title', 'My Site');
    server.run();
});