GithubHelp home page GithubHelp logo

opportunitylivetv / simplehttp2server Goto Github PK

View Code? Open in Web Editor NEW

This project forked from googlechromelabs/simplehttp2server

1.0 3.0 1.0 374 KB

A simple HTTP/2 server for development

License: Other

Shell 1.56% Go 96.22% Ruby 2.22%

simplehttp2server's Introduction

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:

$ go 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:

$ brew tap GoogleChrome/simplehttp2server https://github.com/GoogleChrome/simplehttp2server
$ brew install simplehttp2server

Docker

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

$ docker 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

simplehttp2server [options]
options: 
  -config     string     Config file
  -cors       string     Set allowed origins (default "*")
  -listen     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

{
  "redirects": [
    {
      "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.

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

Headers

{
  "headers": [
    {
      "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.

simplehttp2server's People

Contributors

surma avatar ncruces avatar tjfogarty avatar eduardor2k avatar rongjiecomputer avatar mike-north avatar fippo avatar pem-- avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

martina6hall

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.