createServer

Creates HTTP server

Importing

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

Type declaration

createServer ::  CreateServerConfig -> () -> Promise<ServerIO<HttpServer>>

Parameters

parameter

definition

config

CreateServerConfig

CreateServerConfig

parameter

definition

listener

HttpListener

port

<optional> number

hostname

<optional> string

event$

<optional> HttpServerEffect

options

<optional> ServerOptions

dependencies

<optional> Array<BoundDependency<any>>

Returns

ServerIO<HttpServer>is

Example

import { bindTo } from '@marblejs/core';
import { createServer } from '@marblejs/http';
import { IO } from 'fp-ts/lib/IO';
import { listener } from './http.listener';

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

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

const main: IO<void> = async () =>
  await (await server)();

main();

Last updated