❝A fine HTTP(S) development server for static content❞
Powered by Koa
.
NODE_ENV=development ./static-server.js \
. `# [root_folder]` \
localhost `# [host_name]` \
8020 `# [port_number]` \
localhost `# [certificate_name]`
-
Default value:
localhost
Given, for example –
localhost
, the following certificate files are expected …./localhost.key
: Private key./localhost.csr
: Certificate signing request./localhost.crt
: Certificate
Note: If the certificate files cannot be read, the server uses HTTP instead of HTTPS.
-
Default value:
new Map()
Custom specifications of file name extensions mapped to
Content-Type
HTTP header values. Values for file name extensions not included in the map are determined viaKoa
’s internal file name extension–lookup mechanism.For example, the following data results in files with the file name extension
.mustache
being served with the HTTP headerContent-Type: text/plain
…[ [ "mustache", "text/plain" ] ]
Note: Files without a file name extension default to
Content-Type: text/plain
. -
Default value:
localhost
The host name to which the server is bound.
-
Default value:
8020
The port number to which the server is bound. Must be
80
,443
, or in the range1024
–65535
. -
Default value:
.
The relative path of the root folder served.
-
The
NODE_ENV
environment variable is respected and used for theKoa.env
property if its value is …development
(default)production
# | Name |
---|---|
1 | Root folder |
2 | Host name |
3 | Port number |
4 | Certificate name |
Note: Command-line arguments override settings in the configuration file.
Settings can be specified in a JSON file (static-server.configuration.json
) located in the same folder as the server script.
The file should contain an object with any of the following (optional) properties …
{
"certificate_name": "",
"file_name_extension_media_type_map": [
[ "`${file_name_extension}`", "`${media_type}`" ]
],
"host_name": "",
"port_number": "",
"root_folder": ""
}
Note: Settings in the configuration file are overriden by command-line arguments, if specified.
- Execute the following commands …
openssl genrsa -out localhost.key 4096 && \ openssl req -new -sha256 -key localhost.key -out localhost.csr && \ openssl x509 -req -signkey localhost.key -in localhost.csr -out localhost.crt -days 365
- Respond to the Distinguished Name information prompts as appropriate.
Adapted from https://nodejs.org/api/tls.html#tls_tls_ssl_concepts.
© 2020 – 2023 Nate Gehringer ◦ Backwater Systems