Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/valen-h/server-ii
- Owner: Valen-H
- License: mit
- Created: 2019-05-04T13:51:38.000Z (over 5 years ago)
- Default Branch: staging
- Last Pushed: 2019-05-30T15:20:52.000Z (over 5 years ago)
- Last Synced: 2024-11-06T10:12:30.471Z (3 months ago)
- Topics: fs, http, middleware, node, server, static, templates, typescript
- Language: TypeScript
- Size: 36.1 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Security: SECURITY.md
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));
} //startstart();
```
> Enable builtin middlewares with the `allowmw` option.
> Also take a look in `Classes` to see how things work