@@ -73,10 +73,20 @@ func Convert(c *fiber.Ctx) error {
73
73
// Rewrite the target backend if a mapping rule matches the hostname
74
74
if hostMap , hostMapFound := config .Config .ImageMap [reqHost ]; hostMapFound {
75
75
log .Debugf ("Found host mapping %s -> %s" , reqHostname , hostMap )
76
- targetHostUrl , _ := url .Parse (hostMap )
77
- targetHostName = targetHostUrl .Host
78
- targetHost = targetHostUrl .Scheme + "://" + targetHostUrl .Host
79
- proxyMode = true
76
+
77
+ // Check if hostMap is a URL or local path
78
+ if strings .HasPrefix (hostMap , "http://" ) || strings .HasPrefix (hostMap , "https://" ) {
79
+ // Remote URL mapping
80
+ targetHostUrl , _ := url .Parse (hostMap )
81
+ targetHostName = targetHostUrl .Host
82
+ targetHost = targetHostUrl .Scheme + "://" + targetHostUrl .Host
83
+ proxyMode = true
84
+ } else {
85
+ // Local path mapping
86
+ targetHost = hostMap
87
+ proxyMode = false
88
+ mapMode = true
89
+ }
80
90
} else {
81
91
// There's not matching host mapping, now check for any URI map that apply
82
92
httpRegexpMatcher := regexp .MustCompile (config .HttpRegexp )
@@ -121,7 +131,11 @@ func Convert(c *fiber.Ctx) error {
121
131
// Since here we've already sent non-image file, "raw" is not supported by default in the following code
122
132
if config .AllowAllExtensions && ! helper .CheckImageExtension (filename ) {
123
133
if ! proxyMode {
124
- return c .SendFile (path .Join (config .Config .ImgPath , reqURI ))
134
+ if ! mapMode {
135
+ return c .SendFile (path .Join (config .Config .ImgPath , reqURI ))
136
+ } else {
137
+ return c .SendFile (path .Join (targetHost , reqURI ))
138
+ }
125
139
} else {
126
140
// If the file is not in the ImgPath, we'll have to use the proxy mode to download it
127
141
_ = fetchRemoteImg (realRemoteAddr , targetHostName )
@@ -145,7 +159,7 @@ func Convert(c *fiber.Ctx) error {
145
159
// by default images are hosted in ImgPath
146
160
rawImageAbs = path .Join (config .Config .ImgPath , reqURI )
147
161
} else {
148
- rawImageAbs = reqURI
162
+ rawImageAbs = path . Join ( targetHost , reqURI )
149
163
}
150
164
// detect if source file has changed
151
165
if metadata .Checksum != helper .HashFile (rawImageAbs ) {
0 commit comments