Skip to content
jimmasonPublic

About

Lightweight local development server with hot reload

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

21 Commits

Folders and files

Repository files navigation

gohost

A fast, lightweight, zero-config development server with hot reload for static websites.

Serve any folder over HTTP(S) with automatic browser refresh on file changes.

As a single, dependency free binary, gohost is easy to include in a project or install globally. Supported on most platforms, Gohost is built with local development and testing in mind.

Not intended for production use.


Features

  • Instant static file serving
  • Hot reload (With automatic css/js cache busting)
  • Serves current directory (or specified folder)
  • Custom ports
  • Optionally open in browser
  • SPA mode
  • SSL mode

Usage

 gohost [folder] [--port 8080] [--open] [--spa] [--no-reload] [--ssl] [--index <file>]

Options

   --port <n>     Port to serve on (default: 8080)
   --open         Open in browser after start
   --spa          Enable SPA mode (fallback to index.html)
   --no-reload    Disable automatic reloading
   --install-cert Install ssl cert (requires --cert path/to/cert.pem --key path/to/key.pem flags)
   --ssl          Enable SSL mode (uses installed cert or cert from --cert and --key flags)
   --index <file> Default file to serve when directory is requested (default: index.html)
   --help         Show this help message
   --version      Show version information

Examples

# Serve current directory on http://localhost:8080
gohost

# Serve specific folder
gohost ./public

# Serve on custom port
gohost --port 3000

# Serve folder and open it in browser
gohost ./site --open

# Serve a spa app in the current directory
gohost --spa

# Serve a spa app in the current directory with a custom index file
gohost --spa --index app.html

SSL mode

Gohost can serve over https using a self-signed certificate. The certificate can be provided in one of two ways:

  • Using the --cert and --key flags to specify the path to the certificate and key files each time gohost is run.
  • Using the --install-cert flag to install a self-signed certificate which is used as the default certificate when running gohost with the --ssl flag.

It is recommended (but not required) to use mkcert to generate a certificate and key pair.

 #first generate a self-signed certificate
mkcert -install
mkcert localhost

# install cert using gohost
gohost --install-cert --cert ./localhost.pem --key ./localhost-key.pem

# run Gohost with ssl
gohost --ssl

# The installed cert can be overridden on a per run basis by providing the --cert and --key flags
gohost --ssl --cert ./anothercert.pem --key ./anothercert-key.pem

Hot reload

Gohost can automatically refresh the browser when files are changed. This is achieved by injecting a script (gohost.js) into .html files that will listen for changes to any file and refresh the browser when a change is detected. Gohost automatically adds a version uuid to all .js and .css files to prevent browser caching issues.

This functionality can be disabled by running gohost with the --no-reload flag.

Installation

Linux/MacOS

curl -sSf https://raw.githubusercontent.com/jimmason/gohost/main/scripts/install.sh | sh

Windows

irm https://raw.githubusercontent.com/jimmason/gohost/main/scripts/install.ps1 | iex

Manual installation

  1. Download the binary from the releases page
  2. Add gohost to your PATH manually.

Building from source

  1. Clone the repository
  2. Run go build -o gohost in the root directory
  3. Add gohost to your PATH manually.

About

Lightweight local development server with hot reload

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages