0.6.0-rc1.5 • Published 4 years ago

sierra v0.6.0-rc1.5

Weekly downloads
14
License
MIT
Repository
github
Last release
4 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

4 years ago

0.6.0-rc1.2

4 years ago

0.6.0-rc1.1

4 years ago

0.6.0-rc1.4

4 years ago

0.6.0-rc1.3

4 years ago

0.6.0-rc1.0

4 years ago

0.5.7

5 years ago

0.5.6

5 years ago

0.5.5

5 years ago

0.5.4

5 years ago

0.5.3

5 years ago

0.5.2

5 years ago

0.5.1

5 years ago

0.5.0

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.16

5 years ago

0.3.15

5 years ago

0.3.14

6 years ago

0.3.13

7 years ago

0.3.12

7 years ago

0.3.11

7 years ago

0.3.10

7 years ago

0.3.9

7 years ago

0.3.8

7 years ago

0.3.7

7 years ago

0.3.6

7 years ago

0.3.5

7 years ago

0.3.4

7 years ago

0.3.3

7 years ago

0.3.2

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.0.17

8 years ago

0.0.16

8 years ago

0.0.15

8 years ago

0.0.14

8 years ago

0.0.13

8 years ago

0.0.12

8 years ago

0.0.11

8 years ago

0.0.10

8 years ago

0.0.9

8 years ago

0.0.8

8 years ago

0.0.7

8 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago

0.0.0

8 years ago

0.2.4

9 years ago

0.2.3

9 years ago

0.2.2

9 years ago

0.2.1

9 years ago

0.2.0

9 years ago

0.1.0

9 years ago