{"id":19851599,"url":"https://github.com/albertodonato/h2static","last_synced_at":"2025-05-01T23:31:34.716Z","repository":{"id":57642855,"uuid":"139618203","full_name":"albertodonato/h2static","owner":"albertodonato","description":"Tiny static web server with TLS and HTTP/2 support","archived":false,"fork":false,"pushed_at":"2024-06-25T06:52:53.000Z","size":342,"stargazers_count":16,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-06-25T16:55:06.417Z","etag":null,"topics":["http-server","http2","https-server","json-format","serving-files","static-server","tls"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"eupl-1.2","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/albertodonato.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-07-03T17:41:35.000Z","updated_at":"2024-06-25T06:52:56.000Z","dependencies_parsed_at":"2023-02-18T22:45:58.519Z","dependency_job_id":"43182f48-97bf-4c55-9ee5-fa2f12736224","html_url":"https://github.com/albertodonato/h2static","commit_stats":null,"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/albertodonato%2Fh2static","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/albertodonato%2Fh2static/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/albertodonato%2Fh2static/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/albertodonato%2Fh2static/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/albertodonato","download_url":"https://codeload.github.com/albertodonato/h2static/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224281931,"owners_count":17285755,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["http-server","http2","https-server","json-format","serving-files","static-server","tls"],"created_at":"2024-11-12T13:30:17.239Z","updated_at":"2024-11-12T13:30:17.744Z","avatar_url":"https://github.com/albertodonato.png","language":"Go","readme":"![h2static logo](server/assets/logo.svg)\n\n# Tiny static web server with TLS and HTTP/2 support\n\n[![Build status](https://github.com/albertodonato/h2static/workflows/CI/badge.svg)](https://github.com/albertodonato/h2static/actions?query=workflow%3ACI)\n[![Go Report Card](https://goreportcard.com/badge/github.com/albertodonato/h2static)](https://goreportcard.com/report/github.com/albertodonato/h2static)\n[![Snap Package](https://snapcraft.io/h2static/badge.svg)](https://snapcraft.io/h2static)\n\n\nA minimal HTTP server for serving static files (and websites).\n\nIt provides a few handy features for serving files and static websites:\n\n* support for HTTP/2\n* support for TLS (HTTPS)\n* support for HTTP Basic Authentication\n* directory listing in HTML and JSON format\n* serve `index.html`/`index.htm` files for the contaning directory\n* serve the corresponding `.html`/`.htm` file for a path without the suffix\n  (when such path doesn't exist)\n  \n\nHTML directory listing provides a responsive design to support both desktop\n\n\u003cp align=\"center\"\u003e\u003cimg alt=\"Desktop page\" src=\"images/screen-1.jpg\" width=\"90%\"/\u003e\u003c/p\u003e\n\nand mobile\n\n\u003cp align=\"center\"\u003e\u003cimg alt=\"Mobile page\" src=\"images/screen-2.jpg\" width=\"40%\"/\u003e\u003c/p\u003e\n\n\n## Install\n\nPre-built binaries are available for different achitectures on the [releases\npage](https://github.com/albertodonato/h2static/releases).\n\nIt can be installed directly via\n\n```bash\ngo install github.com/albertodonato/h2static/cmd/h2static@latest\n```\n\nAlternatively, it can be run from the repository simply as\n\n```bash\ngo run ./cmd/h2static\n```\n\nand built with\n\n```bash\ngo build ./cmd/h2static\n```\n\nwhich produces a `h2static` binary.\n\n\n## HTTPS support\n\nTo run the server on HTTPS, a key/certificate pair in PEM format is\nrequired. The service can be run with\n\n```bash\nh2static -tls-cert cert.pem -tls-key key.pem\n```\n\n\n## JSON directory listing\n\nWhen requesting a path that matches a directory, it's possible to get the\nlisting in JSON format by setting the `Accept` header to `application/json` in\nthe request:\n\n```\n$ curl -s -H \"Accept: application/json\" http://localhost:8080/ | jq\n{\n  \"Name\": \"/\",\n  \"IsRoot\": true,\n  \"Entries\": [\n    {\n      \"Name\": \"bar.txt\",\n      \"IsDir\": false,\n      \"Size\": 11\n    },\n    {\n      \"Name\": \"foo.txt\",\n      \"IsDir\": false,\n      \"Size\": 6\n    },\n    {\n      \"Name\": \"subdir\",\n      \"IsDir\": true,\n      \"Size\": 0\n    }\n  ]\n}\n```\n\n\n## Basic-authentication\n\n\nIt's possible to enable Basic-authentication for the static serve via the `--basic-auth authfile` option. The `authfile` should have the following format:\n\n\n```\nuser1:bc547750b92797f955b36112cc9bdd5cddf7d0862151d03a167ada8995aa24a9ad24610b36a68bc02da24141ee51670aea13ed6469099a4453f335cb239db5da\nuser2:92a891f888e79d1c2e8b82663c0f37cc6d61466c508ec62b8132588afe354712b20bb75429aa20aa3ab7cfcc58836c734306b43efd368080a2250831bf7f363f\n```\n\nwhere passwords are SHA-512 hashed. A simple way to generate the hash is via:\n\n```bash\necho -n PASSWORD | sha512sum\n911b0a07a8cacfebc5f1f45596d67017136c950499fa5b4ff6faffa031f3cec7f197853d1660712c154e1f59c60f682e34ea9b5cbd2d8d5adb0c834f963f30de  -\n```\n\nand copying the resulting hash to the file.\n\n\nNote that the password file is read once at startup, subsequent changes to it won't affect authentication.\n\n\n## Usage\n\nFull usage options are as follows:\n\n```\nUsage of h2static:\n\n  -addr string\n        address and port to listen on (default \":8080\")\n  -allow-outside-symlinks\n        allow symlinks with target outside of directory\n  -basic-auth string\n        password file for Basic Auth (each line should be in the form \"user:SHA512-hash\")\n  -css string\n        file to override builtin CSS for listing\n  -debug-addr string\n        address and port to serve /debug URLs on\n  -dir string\n        directory to serve (default \".\")\n  -disable-h2\n        disable HTTP/2 support\n  -disable-index\n        disable directory index\n  -disable-lookup-with-suffix\n        disable matching files with .htm(l) suffix for paths without suffix\n  -log\n        log requests\n  -request-path-prefix string\n        prefix to strip from request path (e.g. when behind a reverse proxy)\n  -show-dotfiles\n        show files whose name starts with a dot\n  -tls-cert string\n        certificate file for TLS connections\n  -tls-key string\n        key file for TLS connections\n  -version\n        print program version and exit\n```\n\n\n## Install from Snap\n\nThe tool can be installed from the [Snap Store](https://snapcraft.io), on\nsystems where Snaps are supported, via\n\n```bash\nsudo snap install h2static\n```\n\nThe `h2static` binary should be available in path.\n\nIt's also possible to configure the service in the snap so that it run\nautomatically.  See `snap info h2static` for details about the available snap\nsettings.\n\n[![Get it from the Snap Store](https://snapcraft.io/static/images/badges/en/snap-store-black.svg)](https://snapcraft.io/h2static)\n\n\n### Snap setup with Let's Encrypt certificates\n\nAssuming [Certbot](https://certbot.eff.org/) is already set up to handle\ncertificate renewals for the domain, a simple hook can be added to update\ncertificates for `h2static`.  The hook could be written to\n`/etc/letsencrypt/renewal-hooks/post/h2static` with the following content:\n\n\n```bash\n#!/bin/bash\n\nDOMAIN=\"example.com\"\nCERTSDIR=\"/etc/letsencrypt/live/$DOMAIN\"\n\nsnap set h2static tls.cert=\"$(\u003c$CERTSDIR/fullchain.pem)\" tls.key=\"$(\u003c$CERTSDIR/privkey.pem)\"\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falbertodonato%2Fh2static","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falbertodonato%2Fh2static","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falbertodonato%2Fh2static/lists"}