1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2025-01-08 10:45:04 +02:00

Add IMGPROXY_BASE_URL param

This commit is contained in:
DarthSim 2018-04-26 17:38:40 +06:00
parent 04871c8b7f
commit bcd9dfe809
3 changed files with 11 additions and 1 deletions

View File

@ -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_QUALITY` — quality of the resulting image, percentage. Default: `80`;
* `IMGPROXY_GZIP_COMPRESSION` — GZip compression level. Default: `5`; * `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 ## Generating the URL
The URL should contain the signature and resize parameters, like this: The URL should contain the signature and resize parameters, like this:

View File

@ -101,6 +101,8 @@ type config struct {
ETagEnabled bool ETagEnabled bool
ETagSignature []byte ETagSignature []byte
BaseURL string
} }
var conf = config{ var conf = config{
@ -155,6 +157,8 @@ func init() {
boolEnvConfig(&conf.ETagEnabled, "IMGPROXY_USE_ETAG") boolEnvConfig(&conf.ETagEnabled, "IMGPROXY_USE_ETAG")
strEnvConfig(&conf.BaseURL, "IMGPROXY_BASE_URL")
if len(conf.Key) == 0 { if len(conf.Key) == 0 {
log.Fatalln("Key is not defined") log.Fatalln("Key is not defined")
} }

View File

@ -106,7 +106,9 @@ func readAndCheckImage(res *http.Response) ([]byte, imageType, error) {
} }
func downloadImage(url string) ([]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 { if err != nil {
return nil, UNKNOWN, err return nil, UNKNOWN, err
} }