@grundstein/commons
Advanced tools
Comparing version 0.0.1 to 0.0.2
{ | ||
"name": "@grundstein/commons", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"author": "Wizards & Witches", | ||
@@ -33,3 +33,3 @@ "homepage": "https://docs.grundstein.it/commons", | ||
"@magic/error": "0.0.10", | ||
"@magic/fs": "0.0.15", | ||
"@magic/fs": "0.0.16", | ||
"@magic/log": "0.1.10", | ||
@@ -39,4 +39,4 @@ "@magic/types": "0.1.16" | ||
"devDependencies": { | ||
"@magic/format": "0.0.29", | ||
"@magic/test": "0.1.74" | ||
"@magic/format": "0.0.30", | ||
"@magic/test": "0.1.75" | ||
}, | ||
@@ -43,0 +43,0 @@ "keywords": [ |
108
README.md
## @grundstein/commons | ||
### WIP. NOT IN PRODUCTION, TESTED AND/OR BENCHMARKED YET! | ||
### WIP. NOT FULLY AUTOMATED, TESTED AND BENCHMARKED YET! | ||
@@ -12,5 +12,3 @@ ### features: | ||
``` | ||
# not published yet, hence no @ before grundstein. | ||
# this makes npm load the library from git. | ||
npm i --save-exact grundstein/commons | ||
npm i --save-exact @grundstein/commons | ||
``` | ||
@@ -20,6 +18,8 @@ | ||
more info soon. | ||
Below are all imports possible from this library. | ||
TODO: Add usage examples. | ||
``` | ||
import commons from '@grundstein/commons' | ||
import commons, { fs, is, lib, log, middleware } from '@grundstein/commons' | ||
@@ -31,1 +31,97 @@ import lib from '@grundstein/commons/lib.mjs' | ||
``` | ||
#### commons.fs | ||
exports [@magic/fs](https://magic.github.io/fs/), a promisified version of fs with some added functionality. | ||
#### commons.is | ||
exports [@magic/is](https://magic/github.io/is/), a comprehensive runtime type checking library. | ||
#### commons.log | ||
serverside logging functionality, basically a fancy wrapper around console.log that outputs a json object. | ||
those logs get collected by systemd and can be viewed and managed using journalctl. | ||
#### commons.lib | ||
various utility functions | ||
##### lib.createServer | ||
Looks for a directory with https certificates, | ||
and starts a nodejs https or http server depending on the existence of said certificates. | ||
```js | ||
import { lib, log } from '@grundstein/commons' | ||
const listener = lib.createServer({ | ||
// this directory has to be readable by the executing user (in prod, this is "grundstein") | ||
certDir: '/absolute/dir/to/certs', | ||
host: '1.2.3.4', | ||
port: '3000', | ||
startTime: log.hrtime(), | ||
}) | ||
``` | ||
##### createSecureContext | ||
used by lib.createServer to get the https context set up. | ||
##### denyRequest | ||
tests if req.url is empty, includes ://, or does not start with '/', | ||
calls req.socket.destroy if malicious request is detected. | ||
##### enhanceRequest | ||
adds req.startTime field. | ||
##### etags | ||
used to check etag values against a cache of files to use 304 headers for cached content. | ||
cache is either built on-demand or using the pre-built etags.csv file that | ||
[@grundstein/prepare-static-files](https://github.com/grundstein/prepare-static-files) | ||
generates. | ||
##### getClientIp | ||
returns the ip address of a request. | ||
by default, this function will replace the last block of the ip address by xxx. | ||
##### getCurrentDate | ||
get a formatted date and time string | ||
##### getFileEncoding | ||
returns 'br', 'gzip', 'deflate', 'buffer' in that order, | ||
depending on contents of req.headers['accept-encoding'] | ||
##### getRequestDuration | ||
returns the time elapsed between two hrtime values, | ||
as a string, normalized to *s*econds, *m*illi*s*econds or *n*ano*s*econds, | ||
and ending with the unit. | ||
##### getProxies | ||
reads config.proxyFile using fs, splits it at newlines and returns the resulting array | ||
##### isSendableFile | ||
checks if file is truthy and has a file.buffer key. | ||
##### formatLog | ||
collects data from request, response and headers, then returns a one-line json string that can be console.log(ged). | ||
##### respond | ||
prepares the headers and body of a response, then sends it to the client and logs it. | ||
##### sendFile | ||
sets Content-Type and Content-Encoding headers, | ||
checks if compressed file exists and accept-encoding accepts it, | ||
then sends the correct content with correct headers using lib.respond | ||
##### sendStream | ||
sends a file as a stream. | ||
#### changelog | ||
##### 0.0.1 | ||
first release | ||
##### 0.0.2 | ||
* add lib.etags | ||
* lib.createServer now wraps the handler function to use denyRequest | ||
* update dependencies |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
57248
31
670
125
+ Added@magic/fs@0.0.16(transitive)
- Removed@magic/fs@0.0.15(transitive)
Updated@magic/fs@0.0.16