From 3497599d030ef1009ccb58fadd3ad1b1cc1acd73 Mon Sep 17 00:00:00 2001 From: Umputun Date: Tue, 8 Jun 2021 00:45:16 -0500 Subject: [PATCH] add comments and fix docs --- README.md | 6 +++--- app/discovery/discovery.go | 10 ++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index b95ea1b..2966beb 100644 --- a/README.md +++ b/README.md @@ -159,9 +159,9 @@ Users may turn the assets server on (off by default) to serve static files. As l In addition to the common assets server, multiple custom assets servers are supported. Each provider has a different way to define such a static rule, and some providers may not support it at all. For example, multiple asset servers make sense in static (command line provider), file provider, and even useful with docker providers, however it makes very little sense with consul catalog provider. -1. static provider - if source element prefixed by `assets:` it will be treated as file-server. For example `*,[assets|spa]:/web,/var/www,` will serve all `/web/*` request with a file server on top of `/var/www` directory. -2. file provider - setting optional fields `assets: true` or `spa:true` -3. docker provider - `reproxy.assets=web-root:location`, i.e. `reproxy.assets=/web:/var/www`. Switching to spa mode done by setting `reproxy.spa` to `1`, `yes` or `true` +1. static provider - if source element prefixed by `assets:` or `spa:` it will be treated as file-server. For example `*,assets:/web,/var/www,` will serve all `/web/*` request with a file server on top of `/var/www` directory. +2. file provider - setting optional fields `assets: true` or `spa: true` +3. docker provider - `reproxy.assets=web-root:location`, i.e. `reproxy.assets=/web:/var/www`. Switching to spa mode done by setting `reproxy.spa` to `yes` or `true` Assets server supports caching control with the `--assets.cache=` parameter. `0s` duration (default) turns caching control off. A duration is a sequence of decimal numbers, each with optional fraction and a unit suffix, such as "300ms", "1.5h" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h" and "d". diff --git a/app/discovery/discovery.go b/app/discovery/discovery.go index f17da2a..84f0115 100644 --- a/app/discovery/discovery.go +++ b/app/discovery/discovery.go @@ -37,9 +37,9 @@ type URLMapper struct { MatchType MatchType RedirectType RedirectType - AssetsLocation string - AssetsWebRoot string - AssetsSPA bool + AssetsLocation string // local FS root location + AssetsWebRoot string // web root location + AssetsSPA bool // spa mode, redirect to webroot/index.html on not found dead bool } @@ -331,6 +331,7 @@ func (s *Service) mergeLists() (res []URLMapper) { return res[i].SrcMatch.String() < res[j].SrcMatch.String() }) + // sort to put assets down in the list sort.Slice(res, func(i, j int) bool { return res[i].MatchType < res[j].MatchType }) @@ -364,6 +365,7 @@ func (s *Service) extendMapper(m URLMapper) URLMapper { return m } + // destination with with / suffix don't need more dst extension if !strings.HasSuffix(src, "/") && m.MatchType == MTProxy { return m } @@ -388,7 +390,7 @@ func (s *Service) extendMapper(m URLMapper) URLMapper { return res } -// redirects process @code prefix and sets redirect type +// redirects process @code prefix and sets redirect type, i.e. "@302 /something" func (s *Service) redirects(m URLMapper) URLMapper { switch { case strings.HasPrefix(m.Dst, "@301 ") && len(m.Dst) > 4: