/reactserv

A Go HTTP server to serve React compiled code (no SSR)

Primary LanguageGoMIT LicenseMIT

Reactserv

HTTP server to serve React static files from memory. You can also set the root URL.

Build status Docker Pulls Docker Stars Image size Image version

Join Slack channel GitHub last commit GitHub commit activity GitHub issues

Features

  • Reads the static React files from disk and serves them from memory
  • Modify in-memory files with the ROOT_URL set, so using a reverse proxy is easier
  • Reloads files in memory on any file change (works on all platforms, and obviously Linux/Docker)
  • Compatible with amd64, 386, arm64, arm32v7, arm32v6, ppc64le and s390x CPU architectures
  • Docker image tags and sizes

Setup

  1. Place your compiled React code in a directory, for example /yourpath/react.

  2. Use the following command:

    docker run -d -p 8000:8000/tcp -v /yourpath/react:/srv:ro qmcgaw/reactserv

    You can also use docker-compose.yml with:

    docker-compose up -d
  3. You can update the image with docker pull qmcgaw/reactserv:latest or use one of tags available

Environment variables

Environment variable Default Possible values Description
LOG_ENCODING console json, console Logging format
LOG_LEVEL info debug, info, warning, error Logging level
LISTENING_PORT 8000 Integer between 1 and 65535 Internal listening TCP port
ROOT_URL / URL path string URL path, used if behind a reverse proxy
ROOT_DIR srv Absolute or relative file path Root filesystem path to read files from
TZ America/Montreal string Timezone

Development

  1. Setup your environment

    Using VSCode and Docker (easier)

    1. Install Docker
      • On Windows, share a drive with Docker Desktop and have the project on that partition
      • On OSX, share your project directory with Docker Desktop
    2. With Visual Studio Code, install the remote containers extension
    3. In Visual Studio Code, press on F1 and select Remote-Containers: Open Folder in Container...
    4. Your dev environment is ready to go!... and it's running in a container 👍 So you can discard it and update it easily!

    Locally

    1. Install Go, Docker and Git

    2. Install Go dependencies with

      go mod download
    3. Install golangci-lint

    4. You might want to use an editor such as Visual Studio Code with the Go extension. Working settings are already in .vscode/settings.json.

  2. Commands available:

    # Build the binary
    go build cmd/app/main.go
    # Test the code
    go test ./...
    # Lint the code
    golangci-lint run
    # Build the Docker image
    docker build -t qmcgaw/reactserv .
  3. See Contributing for more information on how to contribute to this repository.

TODOs

  • Add default favicon.ico
  • Authentication with OAuth or similar

License

This repository is under an MIT license unless otherwise indicated