Coder Social home page Coder Social logo

websrv's Introduction

websrv

This is a little webserver implementation based on chi. The webserver is supposed to serve a folder containing e.g. a static website and is suited to serve a SPA.

The server package contains a collection of http.Handler implementations which may be reused in other projects. The filesystem package contains a readonly in-memory-filesystem implementation.

Server package features

Logs are (without -pretty option) are provided in a GCP compatible JSON format.

The following middleware handler features are provided in the server package:

  • Fallback: Handler that falls back on a configured default path when retrieving a specified set of status codes from the next handler. Very useful for serving a SPA.
  • Headers: Static Headers can be easily configured.
  • Caching: Support via ETag and If-None-Match HTTP-Headers
  • Access-Log: Basic access-logging formatted in a GCP-compatible way.
  • CspReplace and SessionCookie: See my blog about fixing Angular CSP regarding style-src.

Usage

Docker container

You can use the ngergs/websrv docker container, the entrypoint is set to the websrv executable.

Binary build

All releases starting with v1.4.3 have binary builds attached to them for linux, windows and osx.

Compilation from Source

Compile from source:

git clone https://github.com/ngergs/websrv
go build ./cmd/websrv

Usage

The path to the folder to be served has to be provided as command line argument.

Usage: ./websrv {options} [target-path]
Options:
  -conf string
        config file to load

Config file settings

There are a number of various optional settings configured via config files. The config options and documentation can be found in the config.yaml. There is also an example configuration.

Config from env

All config settings can be also set via environment variables. Environment variables take precedence over config file settings. All env config vars start with WEBSRV and follow with the upper-cased config-setting name. You can use underscores to set nested values. To e.g. set the value of

log:
  level: info

the following configuration variable can be used: WEBSRV_LOG_LEVEL=info.

websrv's People

Contributors

ngergs avatar github-actions[bot] avatar

Stargazers

Mickaël Salaün avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.