130002.18.6 • Published 1 year ago
@warren-bank/serve v130002.18.6
serve
Static file serving and directory listing
Fork:
- serve-handler
- forked from tag: 6.1.3
- changes:
- extensive amount of refactoring, rewriting, bug fixes, and new features (too many to list)
- added the dependency resolve-lnk
- when the
symlinksoption is enabled (ex:serve --symlinks), Windows shortcuts are processed in the same way as symbolic links - a Windows shortcut to a file will retrieve its contents
- a Windows shortcut to a directory will list its contents
- nesting multiple Windows directory shortcuts works as expected
- when the
- added the dependency basic-auth
- to allow the
authoption to restrict access using basic authentication
- to allow the
- added the dependency strong-data-uri
- added the dependency cheerio
- to allow the
proxyMiddlewareoption to rewrite the HTML DOM in responses for proxied redirects
- to allow the
- schemas
- forked from tag: 2.19.0
- files:
- changes:
- add: (boolean)
symlinks - add: (boolean)
etag - add: (object)
auth- restrict access using basic auth
- attributes:
- (string)
name - (string)
pass
- (string)
- add: (string)
proxyCookieJar- file path to a persistent text file used by proxied redirects to store cookie data in JSON format
- add: (array)
proxyMiddleware- apply custom middleware to modify the text content in responses for proxied redirects
- shape: array of objects
- attributes of each object:
- (string)
engine- must be one of the following values:
- glob
- route
- regex
- text
- must be one of the following values:
- (string)
source- pattern to compare with the URL of proxied redirect requests
- (string)
type- must be one of the following values:
- html
- json
- js
- text
- must be one of the following values:
- (string)
middleware- holds a stringified function
- produced by:
Function.prototype.toString()
- produced by:
- holds a stringified function
- (boolean)
terminal
- (string)
- usage:
- a
middlewarefunction is only called for a proxied response when:sourcematches the URL of the redirected requestenginedetermines the methodology that is used to matchsourcewith the URL- glob
- uses minimatch
- route
- uses path-to-regexp
- regex
- uses a standard regular expression pattern
- an optional (string)
flagsattribute can add regex modifiers (ex: "i")
- text
- uses the presence of a case-sensitive substring
- an optional (boolean)
exactattribute can add the requirement that the substring must match the entire URL
- glob
typematches the generalized grouping of content-type values to which the data in the response is categorized
- a
middlewarefunction is passed a single parameter, which depends upon thetypeof response data- html
- is passed an instance of cheerio
- allows direct manipulation of DOM elements
- json
- is passed:
{response: data} - where
datais the data structure obtained by parsing the JSON response - allows direct manipulation of the data structure
- is passed:
- js and text
- are passed:
{response: data} - where
datais the raw text response - allows direct manipulation of the text response
- are passed:
- html
- a
- add: (array)
cgiBin- execute cgi-bin scripts and return stdout in response
- shape: array of objects
- attributes of each object:
- (string)
engine- must be one of the following values:
- glob
- route
- regex
- text
- must be one of the following values:
- (string)
source- pattern to compare with the absolute file path for a file that exists and will otherwise be served
- (string)
command- the command-line instruction to execute
- (object)
env- an optional key/value map for environment variables that should exist during execution
- (string)
- usage:
- a
commandis only executed for a requested file path when:sourcematches the absolute file path for a file that exists and will otherwise be served- this file path may be the end result of several
rewrites - this file path is normalized to use a '/' directory separator on all platforms
enginedetermines the methodology that is used to matchsourcewith the absolute file path- glob
- uses minimatch
- route
- uses path-to-regexp
- regex
- uses a standard regular expression pattern
- an optional (string)
flagsattribute can add regex modifiers (ex: "i")
- text
- uses the presence of a case-sensitive substring
- an optional (boolean)
exactattribute can add the requirement that the substring must match the entire URL
- glob
- this file path may be the end result of several
- a
commandcan be any command-line instruction that can execute and write a response to standard output- the current working directory is normalized to the directory that contains the file that matches
source - the following are special tokens that can be used in a
commandwith values that are dynamically interpolated at runtime:{{source}}- the absolute file path that matches
source- enclosed by double quotes
- using the native directory separator
- the absolute file path that matches
{{www-root}}- the absolute directory path for the root of the web server
- using the native directory separator
- the absolute directory path for the root of the web server
{{req-url}}- the URL requested by the client from the server
- enclosed by double quotes
- does not include:
- protocol, hostname, port
- does include:
- pathname, search (querystring)
- the URL requested by the client from the server
- the following are special tokens that can be used in
envvalues that are dynamically interpolated at runtime:{{serve-root}}- the absolute directory path for the root of the
@warren-bank/servepackage- using the native directory separator
- the absolute directory path for the root of the
{{www-root}}- the absolute directory path for the root of the web server
- using the native directory separator
- the absolute directory path for the root of the web server
- the current working directory is normalized to the directory that contains the file that matches
- a
- add: (boolean)
logReq- print a log of all inbound requests
- add: (boolean)
logRes- print a log of all outbound responses
- remove: regex patterns to restrict the set of characters permitted in
keyandvalueattributes of each header - modify: update the
valueattribute of each header to permitnullnullvalue is used to remove a specific response header from matching requests
- add: (boolean)
- serve
- forked from tag: 13.0.2
- changes:
- update the
serve-handlerandschemasdependencies to use the modified versions (above) - update the headers added to all responses when using the
--corscommand-line option- permit requests that include credentials when the 'origin' header is also present
- add: a
reviverfunction to reconstruct/rehydratemiddlewarefunctions in the config object from JSON - add: command-line option
--force-https <listen_uri>- this option is only enabled when
--ssl-certand--ssl-keyare used to--listenon one or more secure endpoints - this option allows the server to also listen on one or more insecure endpoints, which will automatically redirect all requests to the first secure endpoint configured to listen on a numbered port
- this option is only enabled when
- add: command-line option
--ssl- this option was originally added upstream
- in: commit
- from: pull request
- on: Oct 17, 2017
- its original implementation automatically included a static OpenSSL certificate
- published by the external dependency: openssl-self-signed-certificate
- this option was subsequently removed upstream
- in: commit
- from: pull request
- on: Sep 26, 2019
- its updated implementation
- replaced the (old)
--ssloption with (new) options:--ssl-cert,--ssl-key, and--ssl-pass - removed the external dependency: openssl-self-signed-certificate
- enabled
serveto be manually configured to use any OpenSSL certificate
- replaced the (old)
- this option has been restored
- as a shorthand way to automatically configure
serveto use the OpenSSL certificate included in both the git repo and npm package- in directory:
.etc/bin/https/cert
- in directory:
- as a shorthand way to automatically configure
- this option was originally added upstream
- add: command-line option
--delay- this option allows the user to specify a delay in milliseconds, which is applied to all requests to simulate network latency
- update the
- optimizations:
- prevent unnecessary calculation of etag hash
- prevent unnecessary determination of mime-type
- bug fixes:
- config option
public- resolve directory path relative to the root of the web server
- which is determined by a command-line argument,and resolved relative to the current working directory
- resolve directory path relative to the root of the web server
- command-line option
--config- resolve file path relative to the current working directory,rather than the root of the web server
- exit with error code when file path is invalid
- command-line option
--ssl-pass- read the file containing the SSL certificate passphrase as a String rather than a Buffer
- command-line option
--single- only redirect requests that would otherwise return a 404 status code
- config option
Install:
npm install --global "@warren-bank/serve"Usage:
- the short version:
serve <options> - the long version
- the easy way:
- copying from examples
- using some preconfigured scripts
Legal:
- all code belonging to the original projects:
- original copyright and license apply
- all code that I've contributed:
- copyright: Warren Bank
- license: GPL-2.0
130002.18.6
1 year ago
130002.18.5
2 years ago
130002.18.4
2 years ago
130002.18.3
2 years ago
130002.13.0
4 years ago
130002.13.1
4 years ago
130002.17.0
4 years ago
130002.15.0
4 years ago
130002.13.2
4 years ago
130002.13.3
4 years ago
130002.14.0
4 years ago
130002.18.1
4 years ago
130002.18.2
4 years ago
130002.18.0
4 years ago
130002.16.0
4 years ago
130002.12.2
4 years ago
130002.12.1
4 years ago
130002.12.0
4 years ago
130002.11.0
4 years ago
130002.10.1
4 years ago
130002.10.0
4 years ago
130002.9.1
4 years ago
130002.9.0
4 years ago
130002.8.8
4 years ago
130002.8.7
4 years ago
130002.8.6
4 years ago
130002.8.5
4 years ago
130002.8.4
4 years ago
130002.8.3
4 years ago
130002.8.2
4 years ago
130002.8.1
4 years ago
130002.8.0
4 years ago
130002.7.3
4 years ago
130002.7.2
4 years ago
130002.7.1
4 years ago
130002.7.0
4 years ago
130002.6.2
4 years ago
130002.6.1
4 years ago
130002.6.0
4 years ago
130002.5.2
4 years ago
130002.5.1
4 years ago
130002.5.0
4 years ago
130002.4.3
4 years ago
130002.4.2
4 years ago
130002.4.1
4 years ago
130002.4.0
4 years ago
130002.3.1
4 years ago
130002.3.0
4 years ago
130002.2.0
4 years ago
130002.1.0
4 years ago
13.0.2
4 years ago