GoogleChromeLabs/simplehttp2server

Name: simplehttp2server

Owner: GoogleChromeLabs

Description: A simple HTTP/2 server for development

Created: 2015-10-21 13:09:10.0

Updated: 2018-05-24 13:55:31.0

Pushed: 2018-02-23 10:58:37.0

Homepage:

Size: 374

Language: Go

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

simplehttp2server serves the current directory on an HTTP/2.0 capable server. This server is for development purposes only. simplehttp2server takes a JSON config that allows you to configure headers, redirects and URL rewrites in a lightweight JSON format.

The format is partially compatible with Firebase?s JSON config. Please see disclaimer below.

Installation

Binaries

simplehttp2server is go get-able:

 get github.com/GoogleChrome/simplehttp2server

Precompiled binaries can be found in the release section.

Brew

You can also install simplehttp2server using brew if you are on macOS:

ew tap GoogleChrome/simplehttp2server https://github.com/GoogleChrome/simplehttp2server
ew install simplehttp2server
Docker

If you have Docker set up, you can serve the current directory via simplehttp2server using the following command:

cker run -p 5000:5000 -v $PWD:/data surma/simplehttp2server [-config firebase.json]

Usage

Run the simplehttp2server command from the directory you want to serve and go to https://localhost:5000

lehttp2server [options]
ons: 
onfig     string     Config file
ors       string     Set allowed origins (default "*")
isten     string     Port to listen on (default ":5000")
That browser warning

When you navigate to the server?s address (most likely https://localhost:5000), you will probably get a warning about the connection being insecure similar to the following:

Chrome warning about an insecure certificate

This is normal and correct, since the certificate generated by simplehttp2server is self-signed and doesn?t carry the signature of any common certificate authority (CA). All browsers offer a way to temporarily ignore this error and proceed. This is safe to do.

When using Chrome you can enable the allow-insecure-localhost flag on chrome://flags which disable? the certificate warning for localhost. This flag is required if you want to use ServiceWorkers on https://localhost with a self-signed certificate you haven't explicitly “trusted”.

Config

simplehttp2server can be configured with the -config flag and a JSON config file. This way you can add custom headers, rewrite rules and redirects. It is partially compatible with Firebase?s JSON config.

All source fields take the Extglob syntax.

Redirects

edirects": [
{
  "source": "/shortlinks/a",
  "destination": "https://google.com",
  "type": 301
}


Rewrites

Rewrites are useful for SPAs, where all paths return index.html and the routing is taking care of in the app itself. Rewrites are only applied when the original target file does not exist.


ewrites": [
{
  "source": "/app/**",
  "destination": "/index.html"
}


Headers

eaders": [
{
  "source": "/**.html",
  "headers": [
    {
      "key": "Cache-Control",
      "value": "max-age=3600"
    }
  ]
},
{
  "source": "/index.html",
  "headers": [
    {
      "key": "Cache-Control",
      "value": "no-cache"
    },
    {
      "key": "Link",
      "value": "</header.jpg>; rel=preload; as=image, </app.js>; rel=preload; as=script"
    }
  ]
}


For details see the Firebase?s documentation.

Firebase Disclaimer

I haven?t tested if the behavior of simplehttp2server always matches the live server of Firebase, and some options (like trailingSlash and cleanUrls) are completely missing. Please open an issue if you find a discrepancy! The support is not offically endorsed by Firebase (yet ?), so don?t rely on it!

HTTP/2 PUSH

Any Link headers with rel=preload will be translated to a HTTP/2 PUSH, as is common practice on static hosting platforms and CDNs. See the example above.

License

Apache 2.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.