createServer
Creates HTTP server

Importing

1
import { createServer } from '@marblejs/http';
Copied!

Type declaration

1
createServer :: CreateServerConfig -> () -> Promise<ServerIO<HttpServer>>
Copied!

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

1
import { bindTo } from '@marblejs/core';
2
import { createServer } from '@marblejs/http';
3
import { IO } from 'fp-ts/lib/IO';
4
import { listener } from './http.listener';
5
6
const httpsOptions: https.ServerOptions = {
7
key: fs.readFileSync('key.pem'),
8
cert: fs.readFileSync('cert.pem'),
9
};
10
11
const server = createServer({
12
port: 1337,
13
hostname: '127.0.0.1',
14
httpListener,
15
dependencies: [
16
bindTo(fooToken)(foo),
17
],
18
event$: (...args) => merge(
19
listening$(...args),
20
upgrade$(...args),
21
),
22
options: { httpsOptions },
23
});
24
25
const main: IO<void> = async () =>
26
await (await server)();
27
28
main();
Copied!
Last modified 1mo ago