{"id":15870880,"url":"https://github.com/sgreben/http-subst-server","last_synced_at":"2025-04-01T22:25:13.290Z","repository":{"id":80988926,"uuid":"161989537","full_name":"sgreben/http-subst-server","owner":"sgreben","description":"tiny static file server, with dead simple templates (just $VARIABLES). single binary, no dependencies. linux, osx, windows. #golang","archived":false,"fork":false,"pushed_at":"2018-12-17T20:00:33.000Z","size":52,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-07T14:39:33.988Z","etag":null,"topics":["binary","environment-variables","golang","http","server","subst"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sgreben.png","metadata":{"files":{"readme":"README.md","changelog":null,"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-12-16T10:20:57.000Z","updated_at":"2022-04-23T06:24:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"a1125631-bc1d-4c09-878c-53e2e85b8be1","html_url":"https://github.com/sgreben/http-subst-server","commit_stats":{"total_commits":16,"total_committers":1,"mean_commits":16.0,"dds":0.0,"last_synced_commit":"c0b53886406b9c67e9237945ea7e8522abe904e7"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sgreben%2Fhttp-subst-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sgreben%2Fhttp-subst-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sgreben%2Fhttp-subst-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sgreben%2Fhttp-subst-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sgreben","download_url":"https://codeload.github.com/sgreben/http-subst-server/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246719598,"owners_count":20822774,"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":["binary","environment-variables","golang","http","server","subst"],"created_at":"2024-10-06T00:40:38.796Z","updated_at":"2025-04-01T22:25:13.272Z","avatar_url":"https://github.com/sgreben.png","language":"Go","readme":"# http-subst-server\n\n`http-subst-server` is a minimal HTTP server that serves files and renders templates with `$VARIABLES` in them.\n\nA mash-up of [http-file-server](https://github.com/sgreben/http-file-server) and [subst](https://github.com/sgreben/subst).\n\n## Contents\n\n- [Contents](#contents)\n- [Get it](#get-it)\n  - [Using `go get`](#using-go-get)\n  - [Pre-built binary](#pre-built-binary)\n- [Examples](#examples)\n  - [Variables from command-line options](#variables-from-command-line-options)\n  - [Variables from the environment](#variables-from-the-environment)\n  - [Variables and routes from the environment](#variables-and-routes-from-the-environment)\n  - [Variables from files](#variables-from-files)\n  - [Variables from standard input](#variables-from-standard-input)\n- [Usage](#usage)\n\n\n## Get it\n\n### Using `go get`\n\n```sh\ngo get -u github.com/sgreben/http-subst-server\n```\n\n### Pre-built binary\n\n[Download a binary](https://github.com/sgreben/http-subst-server/releases/latest) from the releases page or from the shell:\n\n```sh\n# Linux\ncurl -L https://github.com/sgreben/http-subst-server/releases/download/1.2.9/http-subst-server_1.2.9_linux_x86_64.tar.gz | tar xz\n\n# OS X\ncurl -L https://github.com/sgreben/http-subst-server/releases/download/1.2.9/http-subst-server_1.2.9_osx_x86_64.tar.gz | tar xz\n\n# Windows\ncurl -LO https://github.com/sgreben/http-subst-server/releases/download/1.2.9/http-subst-server_1.2.9_windows_x86_64.zip\nunzip http-subst-server_1.2.9_windows_x86_64.zip\n```\n\n## Examples\n\nThe CLI has the following general syntax:\n\n```text\nhttp-subst-server [OPTIONS] [[ROUTE=]PATH...]\n```\n\nTemplate variables can be set via [command-line options](#variables-from-command-line-options), [environment variables](#variables-from-environment), [files](#variables-from-files), and [standard input](#variables-from-standard-input).\n\n### Variables from command-line options\n\n```sh\n$ cat example/index.html\n$GREETING $SUBJECT\n```\n\n```sh\n$ http-subst-server -v GREETING=hello -v SUBJECT=world /=example\n2018/12/16 09:49:09 serving \"./example\" on \"/\"\n2018/12/16 09:49:09 http-subst-server listening on \":8080\"\n```\n\n\n```sh\n$ curl localhost:8080\nhello world\n```\n\n### Variables from the environment\n\nEnvironment variables with a name prefixed with `SUBST_VAR_` (or a custom prefix set via `-var-prefix`) can be used in the templates. The prefix is stripped from the variable name, so e.g. `$SUBST_VAR_hello` is `$hello` in the templates.\n\n\n```sh\n$ cat example/index.html\n$GREETING $SUBJECT\n```\n\n```sh\n$ export SUBST_VAR_GREETING=hello\n$ export SUBST_VAR_SUBJECT=world\n$ http-subst-server /=example\n2018/12/16 09:49:09 serving \"./example\" on \"/\"\n2018/12/16 09:49:09 http-subst-server listening on \":8080\"\n```\n\n```sh\n$ curl localhost:8080\nhello world\n```\n\nEnvironment variables can also be injected by using the shorthand `-v NAME` (short for `-variable NAME`) instead of `-v NAME=VALUE`. When `=VALUE` is left off, `http-subst-server` sets `NAME` to the value of `$NAME` in the current environment:\n\n```\n$ export GREETING=hello\n$ export SUBJECT=world\n$ http-subst-server -v GREETING -v SUBJECT /=example\n2018/12/16 09:49:09 serving \"./example\" on \"/\"\n2018/12/16 09:49:09 http-subst-server listening on \":8080\"\n```\n\n### Variables and routes from the environment\n\nThe values of environment variables with names prefixed `SUBST_ROUTE_` (or a custom prefix set via `-route-prefix`) are used as routes. Apart from the name prefix, only the value of the environment variable is relevant.\n\n```sh\n$ cat example/index.html\n$GREETING $SUBJECT\n```\n\n```sh\n$ export SUBST_VAR_GREETING=hello\n$ export SUBST_VAR_SUBJECT=world\n$ export SUBST_ROUTE_1=/=example\n$ export SUBST_ROUTE_2=/abc=/tmp\n$ http-subst-server\n2018/12/16 09:49:09 serving \"./example\" on \"/\"\n2018/12/16 09:49:09 serving \"/tmp\" on \"/abc/\"\n2018/12/16 09:49:09 http-subst-server listening on \":8080\"\n```\n\n```sh\n$ curl localhost:8080\nhello world\n```\n\n### Variables from files\n\nYou may specify files containing variable definitions `NAME[=VALUE]` (same syntax as `-variable`/`-v`, one per line) using `-variable-file`/`-f`.\nChanges to the definitions in these files will be picked up without having to restart the server.\n\n```sh\n$ cat example/index.html\n$GREETING $SUBJECT\n```\n\n```sh\n$ http-subst-server -f variables.env /=example\n2018/12/16 09:49:09 serving \"./example\" on \"/\"\n2018/12/16 09:49:09 http-subst-server listening on \":8080\"\n```\n\n```sh\n$ curl localhost:8080\n$GREETING $SUBJECT\n```\n\n```sh\n$ echo GREETING=hello \u003e variables.env\n$ cat variables.env\nGREETING=hello\n```\n\n```sh\n$ curl localhost:8080\nhello $SUBJECT\n```\n\n```sh\n$ echo SUBJECT=world \u003e\u003e variables.env\n$ cat variables.env\nGREETING=hello\nSUBJECT=world\n```\n\n```sh\n$ curl localhost:8080\nhello world\n```\n\n### Variables from standard input\n\nIf the `-variables-from-stdin`/`-i` flag is given, variable definitions `NAME[=VALUE]` (same syntax as `-variable`/`-v`, one per line) are continuously streamed from standard input (until it is closed). New definitions are available to templates immediately.\n\n```sh\n$ cat example/index.html\n$GREETING $SUBJECT\n```\n\n```sh\n$ http-subst-server -i /=example\n2018/12/16 09:49:09 serving \"./example\" on \"/\"\n2018/12/16 09:49:09 http-subst-server listening on \":8080\"\n018/12/16 21:28:17 reading variable definitions NAME[=VALUE] from stdin\nGREETING=foo\nSUBJECT=bar\n```\n\n```sh\n$ curl localhost:8080\nfoo bar\n```\n\n## Usage\n\n```text\nhttp-subst-server [OPTIONS] [[ROUTE=]PATH...]\n```\n\n```text\nUsage of http-subst-server:\n  -a string\n    \t(alias for -addr) (default \":8080\")\n  -addr string\n    \taddress to listen on (environment variable \"ADDR\") (default \":8080\")\n  -escape string\n    \tset the escape string - a '$' preceded by this string is not treated as a variable (default \"\\\\\")\n  -f value\n    \t(alias for -variable-file)\n  -i\t(alias for -variables-from-stdin)\n  -o string\n    \t(alias for -output)\n  -output string\n    \twrite the variable mapping to this file whenever it changes\n  -p int\n    \t(alias for -port)\n  -port int\n    \tport to listen on (overrides -addr port) (environment variable \"PORT\")\n  -q\t(alias for -quiet)\n  -quiet\n    \tdisable all log output (environment variable \"QUIET\")\n  -r value\n    \t(alias for -route)\n  -route value\n    \ta route definition ROUTE=PATH (ROUTE defaults to basename of PATH if omitted)\n  -route-prefix string\n    \tuse values of environment variables with this prefix as routes (default \"SUBST_ROUTE_\")\n  -template-suffix string\n    \treplace $variables in files with this suffix (default \".html\")\n  -undefined value\n    \thandling of undefined $variables, one of [ignore empty error] (default ignore) (default ignore)\n  -v value\n    \t(alias for -variable)\n  -var-prefix string\n    \tuse environment variables with this prefix in templates (default \"SUBST_VAR_\")\n  -variable value\n    \ta variable definition NAME[=VALUE] (if the value is omitted, the value of the environment variable with the given name is used)\n  -variable-file value\n    \ta file consisting of lines with one variable definition NAME[=VALUE] per line\n  -variable-file-reload duration\n    \treload interval for variable files (default 1s)\n  -variables-from-stdin\n    \tread lines with variable definitions NAME[=VALUE] from stdin\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsgreben%2Fhttp-subst-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsgreben%2Fhttp-subst-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsgreben%2Fhttp-subst-server/lists"}