diff --git a/README.md b/README.md index 8d8ee07c..c2e37e34 100644 --- a/README.md +++ b/README.md @@ -164,6 +164,10 @@ You can also specify a secret to enable authorization with the HTTP `Authorizati * `IMGPROXY_QUALITY` — quality of the resulting image, percentage. Default: `80`; * `IMGPROXY_GZIP_COMPRESSION` — GZip compression level. Default: `5`; +#### Miscellaneous + +* `IMGPROXY_BASE_URL` - base URL part which will be added to every requestsd image URL. For example, if base URL is `http://example.com/images` and `/path/to/image.png` is requested, imgproxy will download the image from `http://example.com/images/path/to/image.png`. Default: blank. + ## Generating the URL The URL should contain the signature and resize parameters, like this: diff --git a/config.go b/config.go index a1dbfabd..1be29560 100644 --- a/config.go +++ b/config.go @@ -101,6 +101,8 @@ type config struct { ETagEnabled bool ETagSignature []byte + + BaseURL string } var conf = config{ @@ -155,6 +157,8 @@ func init() { boolEnvConfig(&conf.ETagEnabled, "IMGPROXY_USE_ETAG") + strEnvConfig(&conf.BaseURL, "IMGPROXY_BASE_URL") + if len(conf.Key) == 0 { log.Fatalln("Key is not defined") } diff --git a/download.go b/download.go index 3c8441a4..df0622ad 100644 --- a/download.go +++ b/download.go @@ -106,7 +106,9 @@ func readAndCheckImage(res *http.Response) ([]byte, imageType, error) { } func downloadImage(url string) ([]byte, imageType, error) { - res, err := downloadClient.Get(url) + fullURL := fmt.Sprintf("%s%s", conf.BaseURL, url) + + res, err := downloadClient.Get(fullURL) if err != nil { return nil, UNKNOWN, err }