simplehttp2server

A simple HTTP/2 server for development

  • 所有者: GoogleChromeLabs/simplehttp2server
  • 平台:
  • 许可证: Other
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

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.

主要指标

概览
名称与所有者GoogleChromeLabs/simplehttp2server
主编程语言Go
编程语言Go (语言数: 4)
平台
许可证Other
所有者活动
创建于2015-10-21 13:09:10
推送于2023-12-31 11:53:37
最后一次提交2019-03-14 14:59:34
发布数19
最新版本名称3.1.3 (发布于 )
第一版名称1.0.0 (发布于 )
用户参与
星数1.7k
关注者数50
派生数99
提交数72
已启用问题?
问题数32
打开的问题数5
拉请求数9
打开的拉请求数1
关闭的拉请求数4
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?