0.6.0-rc1.5 • Published 3 years ago

sierra v0.6.0-rc1.5

Weekly downloads
14
License
MIT
Repository
github
Last release
3 years ago

Sierra

Node.js CI npm version

Middleware for your Node.js Server Application.

Sierra provides Promise based Middleware and HTTP Request handling.

Create a Handler

Sierra uses a Middleware pipeline to process HTTP Requests. To get up and running, create a new Handler instance.

import { createHandler } from 'sierra';

const handler = new createHandler();

Add Middleware

Middleware can be added to the Handler.

handler.use((context, value) => {
    return 'output';
});

Handler.use calls can be chained together. This is especially useful for strong typing.

interface BodyContext {
    body: {
        value: string;
    }
}

interface SessionContext {
    session: {
        user: string;
    }
}

const handler = createHandler()
    .use<BodyContext>(({ data }) => {
        data.body = {
            value: 'test',
        };
    })
    .use<SessionContext>(({ data }) => {
        data.session = {
            user: 'admin',
        };
    })
    .use(({ data }) => {
        const { body, session } = data;
        const { value } = body;
        const { user } = session;
        return {
            value,
            user,
        };
    });

Create a Server

A Handler.callback function may be passed to a Node.js http.Server instance.

import { createServer } from 'http';
import { createHandler } from 'sierra';

const handler = createHandler();

const server = createServer(handler.callback);

server.listen(80);

A special Promise based PromiseServer is also provided.

When using createServer from Sierra, you may pass Handler instances directly.

import { createHandler, createServer } from 'sierra';

const handler = createHandler();

const server = createServer(handler);

server.start(80);
0.6.0-rc1.5

3 years ago

0.6.0-rc1.2

3 years ago

0.6.0-rc1.1

3 years ago

0.6.0-rc1.4

3 years ago

0.6.0-rc1.3

3 years ago

0.6.0-rc1.0

3 years ago

0.5.7

4 years ago

0.5.6

4 years ago

0.5.5

4 years ago

0.5.4

4 years ago

0.5.3

4 years ago

0.5.2

4 years ago

0.5.1

4 years ago

0.5.0

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.3.16

4 years ago

0.3.15

4 years ago

0.3.14

5 years ago

0.3.13

6 years ago

0.3.12

6 years ago

0.3.11

6 years ago

0.3.10

6 years ago

0.3.9

6 years ago

0.3.8

6 years ago

0.3.7

6 years ago

0.3.6

6 years ago

0.3.5

6 years ago

0.3.4

6 years ago

0.3.3

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.0.17

6 years ago

0.0.16

6 years ago

0.0.15

6 years ago

0.0.14

6 years ago

0.0.13

6 years ago

0.0.12

6 years ago

0.0.11

6 years ago

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

7 years ago

0.0.1

7 years ago

0.0.0

7 years ago

0.2.4

8 years ago

0.2.3

8 years ago

0.2.2

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.0

8 years ago