GithubHelp home page GithubHelp logo

imgix / imgix-webfolder-router Goto Github PK

View Code? Open in Web Editor NEW
1.0 17.0 0.0 128 KB

A simple node.js router to allow multiple Base URLs for imgix Web Folders

Home Page: http://www.imgix.com

JavaScript 100.00%

imgix-webfolder-router's Introduction

imgix logo

imgix-webfolder-router

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.

Example Overview

This example overview uses an example configuration for "yourcompany.com" to show you how this works.

Getting started

Clone this repo and run npm install.

Configuration

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
}

Running

node server.js # for example running on yourcompany.com

Creating imgix source

In the imgix webapp a new "Web Folder" source would look like this:

imgix Web Folder Source create screenshot

Route/Fetch Examples

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

Warnings and Recommendations

  • 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.

Alternatives

You can achieve similar functionality by running a reverse proxy. For further details on this method contact [email protected]

imgix-webfolder-router's People

Contributors

jacktasia avatar

Stargazers

Hardik Shah avatar

Watchers

Jeremy Larkin avatar  avatar James Young avatar Jonathan Freedman avatar Jason Eberle avatar Glenn avatar James Cloos avatar Hardik Shah avatar Alfonso avatar Kaylie DeHart avatar Richard Kuo avatar Alice Lawrie avatar Amanda Hassoun avatar Pedro Aguilar avatar Matt Laguardia avatar Sherwin Heydarbeygi avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.