createServer

Marble.j abstraction over Node.js server creation with additional features.

Importing

import { createServer } from '@marblejs/core';

Type declaration

createServer ::  CreateServerConfig -> Server

Parameters

parameter

definition

config

CreateServerConfig

CreateServerConfig

parameter

definition

httpListener

HttpListener

port

<optional> number

hostname

<optional> string

event$

<optional> HttpServerEffect

options

<optional> ServerOptions

dependencies

<optional> Array<BoundDependency<any>>

Returns

parameter

definitoin

run

boolean? -> https.Server | http.Server

info

ServerInfo

server

https.Server | http.Server

ServerInfo

parameter

definitoin

routing

Array<RoutingItem>

Example

index.ts
import httpListener from './http.listener';
import { createServer, bindTo } from '@marblejs/core';

const httpsOptions: https.ServerOptions = {
  key: fs.readFileSync('key.pem'),
  cert: fs.readFileSync('cert.pem'),
};

export const server = createServer({
  port: 1337,
  hostname: '127.0.0.1',
  httpListener,
  dependencies: [
    bindTo(fooToken)(foo),
  ],
  event$: (...args) => merge(
    listening$(...args),
    upgrade$(...args),
  ),
  options: { httpsOptions },
});

server.run(
  process.env.NODE_ENV !== 'test'
);

Last updated