1.1.6 • Published 5 months ago

siuje v1.1.6

Weekly downloads
-
License
BSD Source Code
Repository
-
Last release
5 months ago

Siuje

A light framework for http backend server

What is Siuje

It is a very very tiny web server library, for Node.js.

How to Use

Startup the Server

// index.js
const siuje = require("siuje");
siuje.work({ host: "127.0.0.1", port: 3000 })

Schedule a Job

// index.js
const siuje = require("siuje");
siuje.when( "12:00" ).work( 
	async () => {
		// do some work here
	}
);
siuje.work({ host: "127.0.0.1", port: 3000 })

or

// index.js
const siuje = require("siuje");
const {second, minute, hour, day} = require("siuje/utime");
siuje.every( second(10) ).repeat(
	async () => {
		// do something
	}
)//.until( () => true|false );
siuje.work({ host: "127.0.0.1", port: 3000 })

Handle a HTTP Request

// index.js
const siuje = require("siuje");

// sample for middleware
const set_header = headers => {
	return (req, ctrl) => next => {
		ctrl( headers );
		return next(req, ctrl);
	}
}

siuje.meet("/test")
	.use( set_header({"Server": "siuje"}) )
	.serve( async (req, ctrl) => {
		return "hello, world";
	});

siuje.work({ host: "127.0.0.1", port: 3000 })

Middleware Presets

You can use siuje.seq to embed multiple middlewares into one middleware:

// index.js
const siuje = require("./siuje");

// sample for middleware
const set_header = headers => {
        return (req, ctrl) => next => {
                ctrl( headers );
                return next(req, ctrl);
        }
}

const my_headers = siuje.seq(
        set_header({"connection": "keep-alive"}),
        set_header({"access-control-allow-origin": "*"})
);

siuje.meet("/test")
        .use( set_header({"Server": "siuje"}) )
        .use( my_headers )
        .serve( async (req, ctrl) => {
                return "hello, world";
        });

siuje.work({ host: "127.0.0.1", port: 22181 })

How about bodyParser?

You should implement your middleware for body parser.

How to Deploy in Serverless?

You should use siujeless for serverless platform.

Detail for req/ctrl and next

  • req is the instance for http.IncomingMessage
  • next is only a function to run the next middleware
  • ctrl is a handler for building the response
    1. when you give a number to ctrl, it means that you want to set the http response status code
    2. when you give an object to ctrl, it means that you want to set the http response header
    3. when you give a string(json/query/else) to ctrl, it means that you want to set the http response mine type
    4. when you give an empty to ctrl, it means that you want to get the current status/header and mine type
    5. when you give an error object to ctrl, it will give a 500 for response
    6. when you give a function to ctrl, your function will be call with the http response object and a setter to custom your output
1.1.1

8 months ago

1.1.0

8 months ago

1.1.6

5 months ago

1.1.5

5 months ago

1.0.6

9 months ago

1.1.4

5 months ago

1.0.5

9 months ago

1.1.3

6 months ago

1.1.2

6 months ago

1.0.11

9 months ago

1.0.4

11 months ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago