hastatic/README.md

56 lines
2.2 KiB
Markdown
Raw Permalink Normal View History

2018-07-21 09:12:42 +05:30
# hastatic
2018-07-22 08:13:01 +05:30
[![Docker Build Status](https://img.shields.io/docker/build/abhin4v/hastatic.svg?style=flat-square)](https://hub.docker.com/r/abhin4v/hastatic/) [![Docker Pulls](https://img.shields.io/docker/pulls/abhin4v/hastatic.svg?style=flat-square)](https://hub.docker.com/r/abhin4v/hastatic/) [![MicroBadger Size](https://img.shields.io/microbadger/image-size/abhin4v/hastatic.svg?style=flat-square)](https://hub.docker.com/r/abhin4v/hastatic/)
2018-07-21 10:26:59 +05:30
2018-07-23 16:15:10 +05:30
_hastatic_ is a very small web server for serving static files from a Docker container.
2018-07-21 09:12:42 +05:30
## Features
2018-07-23 16:15:10 +05:30
- A lightweight web server, just 5 MB in size.
- [Built for Docker](https://hub.docker.com/r/abhin4v/hastatic/).
2018-07-21 19:00:42 +05:30
- Supports HTTPS.
2018-07-21 09:12:42 +05:30
- Supports custom 404 file.
- Supports custom index files for URLs ending with "/".
2018-07-21 10:26:59 +05:30
- Takes care to not serve hidden files.
2018-07-21 09:12:42 +05:30
- Adds caching headers automatically.
2018-08-27 22:31:09 +05:30
- Adds security headers automatically.
2018-07-22 08:13:01 +05:30
- Caches file descriptors and info for better performance.
2018-07-21 09:12:42 +05:30
## Usage
Create a Dockerfile for your website, deriving from `abhin4v/hastatic`:
```dockerfile
FROM abhin4v/hastatic:latest
COPY mywebsite /opt/mywebsite
WORKDIR /opt/mywebsite
CMD ["/usr/bin/hastatic"]
```
Build and run:
2018-07-21 19:00:42 +05:30
```bash
2018-07-21 09:12:42 +05:30
$ docker build -t mywebsite .
2018-07-21 19:00:42 +05:30
$ # run with default configs
$ docker run -p 8080:3000 mywebsite
$ # run with custom configs
2018-07-21 09:12:42 +05:30
$ docker run -e PORT=2000 -e NF_FILE=404.html -e IDX_FILE=index.html -p 8080:2000 mywebsite
2018-07-21 19:00:42 +05:30
$ # run with HTTPS support
$ docker run -e TLS_CERT_FILE=certificate.pem -e TLS_KEY_FILE=key.pem -p 443:3000 mywebsite
2018-07-21 09:12:42 +05:30
```
## Configuration
The Docker image supports these environment variable for configuration:
- PORT: the port to run the web server on, default: 3000
- NF_FILE: name of the custom 404 file, default: `404.html`
- IDX_FILE: name of the custom index files, default: `index.html`
2018-07-21 19:00:42 +05:30
- TLS_CERT_FILE: TLS certification file, optional, required for HTTPS support
- TLS_KEY_FILE: TLS key file, optional, required for HTTPS support
2018-07-21 09:12:42 +05:30
## Internals
2019-07-10 23:03:29 +05:30
_hastatic_ is written in Haskell, just [70 lines](https://github.com/abhin4v/hastatic/blob/master/src/Main.hs#L25) of it. It uses the excellent [Warp](https://hackage.haskell.org/package/warp) server underneath with the [warp-tls](https://hackage.haskell.org/package/warp-tls) package for HTTPS support.