package module
Version: v0.5.0 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Jul 3, 2020 License: MIT Imports: 1 Imported by: 0


serve is a static http server anywhere you need one.

GoDoc Build Status codecov Go Report Card Mentioned in Awesome Go

GitHub Release Docker Cloud Automated build Docker Cloud Build Status Docker Pulls

Deploy to Heroku


It's basically python -m SimpleHTTPServer 8080 written in Go, because who can remember that many letters?

  • CORS support
  • Request logging
  • net/http compatible


serve can be installed in a handful of ways:

Homebrew on macOS

If you are using Homebrew on macOS, you can install serve with the following command:

brew install syntaqx/tap/serve

The official syntaqx/serve image is available on Docker Hub.

To get started, try hosting a directory from your docker host:

docker run -v .:/var/www:ro -d syntaqx/serve

Alternatively, a simple Dockerfile can be used to generate a new image that includes the necessary content:

FROM syntaqx/serve
COPY . /var/www

Place this in the same directory as your content, then build and run the container:

docker build -t some-content-serve .
docker run --name some-serve -d some-content-serve
Exposing an external port
docker run --name some-serve -d -p 8080:8080 some-content-serve

Then you can navigate to http://localhost:8080/ or http://host-ip:8080/ in your browser.

Using environment variables for configuration

Currently, serve only supports using the PORT environment variable for setting the listening port. All other configurations are available as CLI flags.

In future releases, most configurations will be settable from both the CLI flag as well as a compatible environment variable, aligning with the expectations of a 12factor app. But, that will require a fair amount of work before the functionality is made available.

Here's an example using docker-compose.yml to configure serve to use HTTPS:

version: '3'
    image: syntaqx/serve
      - ./static:/var/www
      - ./fixtures:/etc/ssl
      - PORT=1234
      - 1234
    command: serve -ssl -cert=/etc/ssl/cert.pem -key=/etc/ssl/key.pem -dir=/var/www

The project repository provides an example docker-compose that implements a variety of common use-cases for serve. Feel free to use those to help you get started.

Download the binary

Quickly download install the latest release:

curl -sfL | sh

Or manually download the latest release binary for your system and architecture and install it into your $PATH.

From source

To build from source, check out the instructions on getting started with development.


serve [options] [path]

[path] defaults to . (relative path to the current directory)

Then simply open your browser to http://localhost:8080 to view your server.


The following configuration options are available:

  • --host host address to bind to (defaults to
  • --port listening port (defaults to 8080)
  • --ssl enable https (defaults to false)
  • --cert path to the ssl cert file (defaults to cert.pem)
  • --key path to the ssl key file (defaults to key.pem)
  • --dir directory path to serve (defaults to ., also configurable by arg[0])
  • --users path to users file (defaults to users.dat); file should contain lines of username:password in plain text


To develop serve or interact with its source code in any meaningful way, be sure you have the following installed:


Note: While the tooling isn't explicitly required in order to build and run the project, it's for everyone's benefit that you leverage it.


You can download and install the project from GitHub by simply running:

git clone && cd $(basename $_ .git)
make install

This will install serve into your $GOPATH/bin directory, which assuming is properly appended to your $PATH, can now be used:

$ serve version
serve version v0.0.6-8-g5074d63 windows/amd64

Using serve manually

Besides running serve using the provided binary, you can also embed a serve.FileServer into your own Go program:

package main

import (


func main() {
    fs := serve.NewFileServer()
    log.Fatal(http.ListenAndServe(":8080", fs))


serve is open source software released under the MIT license.

As with all Docker images, these likely also contain other software which may be under other licenses (such as Bash, etc from the base distribution, along with any direct or indirect dependencies of the primary software being contained).

As for any pre-built image usage, it is the image user's responsibility to ensure that any use of this image complies with any relevant licenses for all software contained within.



Package serve provides a static http server anywhere you need one.



This section is empty.


This section is empty.


This section is empty.


type FileServer added in v0.0.6

type FileServer struct {
	// contains filtered or unexported fields

FileServer wraps an http.FileServer.

func NewFileServer added in v0.0.6

func NewFileServer(options ...Options) *FileServer

NewFileServer initializes a FileServer.

func (*FileServer) ServeHTTP added in v0.0.6

func (fs *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the net/http.Handler interface.

func (*FileServer) Use added in v0.0.6

func (fs *FileServer) Use(mws ...func(http.Handler) http.Handler)

Use wraps the Handler with middleware(s).

type Options added in v0.0.8

type Options struct {
	// Directory is the root directory from which to serve files.
	Directory string

	// Prefix is a filepath prefix that should be ignored by the FileServer.
	Prefix string

Options is a struct for specifying configuration options for a FileServer.

Source Files


Path Synopsis
Package main implements the runtime for the serve binary.
Package main implements the runtime for the serve binary.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL