A static server in Go, supporting hosting static files in the no-trailing-slash version.
Get and install the repository using go get
.
go get -u -v github.com/zhanbei/static-server
There are multiple entrances for several standalone applications, lightweight and special-purposed, or heavy and powerful.
- A/The Simple Static Site Server
static-server
assss
zss
- Lightweight VHSS
vhssl
- VHSS with MongoDB Driver
vhssdb
- Load configures and combine with interfaces.
Support multiple targets(file/stdout/files/mongodb) in multiple(possible) formats(text(common/combined/extended)/json/custom).
Formats\Targets | Stdout | File(s) | MongoDB |
---|---|---|---|
Text | +++ |
++ |
--- |
JSON | + |
+++ |
--- |
BSON | --- |
--- |
+++ |
Tools to convert between BSON
, JSON
, and Text
may be needed.
- Server
- Virtual Hosting
false
- Whether to enable virtual hosting; @see https://en.wikipedia.org/wiki/Virtual_hosting
- No Trailing Slash
false
- Hosting static files in the no-trailing-slash mode.
- Directory Listing
false
- Listing files of a directory if the
index.html
is not found when in the normal mode.
- Listing files of a directory if the
- TrustProxyIp
true
- This server will be running behind a reverse proxy,
and prefer to fetch the remote ip from header [
X-Remote-Addr
>X-Forwarded-For
>IP
] overctx.Request.Ip
.
- This server will be running behind a reverse proxy,
and prefer to fetch the remote ip from header [
- Virtual Hosting
- Loggers
- Enabled
false
- Format
"text" | "json"
- Per Host
false
- A log file per host.
- Target
"stdout" | ${file}
${dir}
- The value should be
"stdout"|${file}
if theperHost
option is false. - The value should be
${dir}
if theperHost
option is true.
- The value should be
- Enabled
- Mongo
- Enabled
false
- Connection
"mongodb://${hostname}:${port=27017}"
- Database
string
- Collection Prefix
"logging.vhss"
- Enabled
Libraries to receive arguments and options.
- Command-line Arguments
- Configuration File
# Serving the current folder on a specific port.
static-server 1234
# Serving a specific folder on a specific port.
static-server 1234 ./some-folder/site-root
# Serving a folder in the no-trailing-slash mode.
static-server --no-trailing-slash 1234 ./some-folder/site-root
# Serving a folder in the no-trailing-slash mode with virtual hosting.
static-server --no-trailing-slash --enable-virtual-hosting 1234 ./some-folder/site-root
Run static-server --help
to get the help text, like shown below:
NAME:
static-server - A static server in Go, supporting hosting static files in the no-trailing-slash version.
USAGE:
static-server [global options] [<http-address>:]<http-port> <www-root-directory>
VERSION:
0.9.0
DESCRIPTION:
A static server in Go, supporting hosting static files in the no-trailing-slash version.
COMMANDS:
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--enable-virtual-hosting Whether to enable virtual hosting; @see https://en.wikipedia.org/wiki/Virtual_hosting
--no-trailing-slash Hosting static files in the no-trailing-slash mode.
--help, -h show help
--version, -v print the version