Skip to content

Commit

Permalink
Allow disabling HTML browse pages (mat#72)
Browse files Browse the repository at this point in the history
The environment variable DISABLE_BROWSE_PAGES can be used to disable
all HTML pages which can be used to minimize the footprint of the
iconserver.
  • Loading branch information
koesie10 authored Jan 24, 2022
1 parent 695fa4c commit 431a4be
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
1 change: 1 addition & 0 deletions Readme.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ There is not a lot to configure, but these environment variables exist
| `CORS_ALLOWED_ORIGINS` | Comma-separated, passed to middleware | |
| `CORS_ALLOW_CREDENTIALS` | Boolean, passed to middleware | |
| `CORS_DEBUG` | Boolean, passed to middleware | |
| `DISABLE_BROWSE_PAGES` | Boolean, if true, the server will not serve any of the HTML pages | false |
| `HOST_ONLY_DOMAINS` | | \* |
| `HTTP_CLIENT_TIMEOUT` | Timeout used for HTTP requests. Supports units like ms, s, m. | 5s |
| `HTTP_MAX_AGE_DURATION` | Cache duration for all dynamically generated HTTP responses. Supports units like ms, s, m. | 720h _(30 days)_ |
Expand Down
23 changes: 14 additions & 9 deletions besticon/iconserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,20 +254,25 @@ func renderHTMLTemplate(w http.ResponseWriter, httpStatus int, templ *template.T
}

func startServer(port string, address string) {
registerHandler("/", indexHandler)
registerHandler("/icons", iconsHandler)
registerHandler("/icon", iconHandler)
registerHandler("/popular", popularHandler)
registerHandler("/allicons.json", alliconsHandler)
registerHandler("/lettericons/", lettericonHandler)

serveAsset("/pure-0.5.0-min.css", "pure-0.5.0-min.css", oneYear)
serveAsset("/grids-responsive-0.5.0-min.css", "grids-responsive-0.5.0-min.css", oneYear)
serveAsset("/main-min.css", "main-min.css", oneYear)
disableBrowsePages := getTrueFromEnv("DISABLE_BROWSE_PAGES")

serveAsset("/icon.svg", "icon.svg", oneYear)
serveAsset("/favicon.ico", "favicon.ico", oneYear)
serveAsset("/apple-touch-icon.png", "apple-touch-icon.png", oneYear)
if !disableBrowsePages {
registerHandler("/", indexHandler)
registerHandler("/icons", iconsHandler)
registerHandler("/popular", popularHandler)

serveAsset("/pure-0.5.0-min.css", "pure-0.5.0-min.css", oneYear)
serveAsset("/grids-responsive-0.5.0-min.css", "grids-responsive-0.5.0-min.css", oneYear)
serveAsset("/main-min.css", "main-min.css", oneYear)

serveAsset("/icon.svg", "icon.svg", oneYear)
serveAsset("/favicon.ico", "favicon.ico", oneYear)
serveAsset("/apple-touch-icon.png", "apple-touch-icon.png", oneYear)
}

metricsPath := getenvOrFallback("METRICS_PATH", "/metrics")

Expand Down

0 comments on commit 431a4be

Please sign in to comment.