A node.js server to map multiple top-level folders
to Base URLs
. When you point an imgix "Web Folder" source's Base URL at this server then you can effectively have multiple "Web Folder" imgix sources but only use one. This also allows you to add more Base URLs
to a single imgix hostname by simply updating the server's config file.
This example overview uses an example configuration for "yourcompany.com" to show you how this works.
Clone this repo and run npm install
.
Create a configuration file by copying the template cp config.example.js config.js
. As an example, we make a fake config for "yourcompany.com".
module.exports = {
webFolderRoutes: {
// keys will be the top-level paths that will point to a Base URL
"blog": "http://blog.yourcompany.com/wp-content/",
"site": "http://yourcompany.com/images/",
"app": "http://www.example.com/application/v2/storage/assets"
},
port: 9444
}
node server.js # for example running on yourcompany.com
In the imgix webapp a new "Web Folder" source would look like this:
So now the single http://yourcompany.imgix.net
can fetch images from multiple Base URLs by using the top-level paths that were defined in your config.js
.
"site" example
http://yourcompany.imgix.net/site/team/our_ceo.jpg
=> http://yourcompany.com/images/team/our_ceo.jpg
"blog" example
http://yourcompany.imgix.net/blog/uploads/2013/01/photo.jpg
=> http://blog.yourcompany.com/wp-content/uploads/2013/01/photo.jpg
"app" example
http://yourcompany.imgix.net/app/logo.jpg
=> http://www.example.com/application/v2/storage/assets/logo.jpg
- This will potentially cause slower fetch times due to the use of redirects. This only applies to the first time the image is requested via imgix or when the cache expires.
- Be careful changing the Base URL on a previously used top-level folder, because any previously requested images from the old Base URL will have been cached by the CDN. While it's unlikely there will be a collision with a change, you may still want to purge images that were cached using the old Base URL.
- Run this process under supervision
- This server would be a single-point of failure for images. It may be necessary to run this behind a load balancer.
You can achieve similar functionality by running a reverse proxy. For further details on this method contact [email protected]