Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/valen-h/server-ii

A Server framework with middleware support.
https://github.com/valen-h/server-ii

fs http middleware node server static templates typescript

Last synced: about 1 month ago
JSON representation

A Server framework with middleware support.

Awesome Lists containing this project

README

        


# V-Serv-II

***

## Features

1. Middlewares
* Propagating
* Builtin / Custom
2. Content-Type mapping
3. Path-URL mapping customization
4. Port customization
5. Templating/Indexing
6. Event-Oriented
7. Caching

### (Builtin) Middlewares

1. fix - Fixes incorrect URLs
* TODO: .xjs -> .jsx etc...
2. directory - Serves index or performs directory indexing
* .noindex (customisable) - empty to block indexing, fill to block specific files
* files starting with '__' (customisable) - blocked from indexing by default
* TODOs: .notmpl - no templating (for .jsx files mostly), and a special request to fetch raw and bypass translation
3. static - Serves raw content and compiles templated content
* TODO: Add caching
* Templated content: .xjs, .htmx, .htmlx, .cssx
4. end - Applies appropriate headers and ends requests
5. TODO: secure - Prevents bruteforcing / DoS (-> HTTP 429)

> Templated content example.htmx: `Hello $$usr$$!`. Translated during serving, change templating characters through server options.

## Usage

```javascript
const server = require("vale-server-ii").Server,
classes = require("../dist/lib/Classes").Classes;

async function start() {
srv = await server.setup({ }); /**@param {Classes.Options.ServerOptions} opts - leave empty fields for default*/
await srv.bind(); //listen()
await srv.bind(new classes.Middleware("test", [ "end" ], [ "static" ], async function body(req, res, event) {
event.server._debug(event.reqcntr, "(TEST.TS) PASSED.");
return event.pass("passed");
}
)); //bind custom middleware
console.debug("Server started...");
srv.on("log", console.log);
srv.on("request", (req, res) => console.debug("(INDEX.JS) REQ:", req.url));
} //start

start();
```

> Enable builtin middlewares with the `allowmw` option.
> Also take a look in `Classes` to see how things work