Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Using Fireplace with Zamboni

Andy McKay edited this page Dec 13, 2013 · 10 revisions

If you want to run Fireplace locally in a way that's similar to production, you can use nginx. The following snippets are nginx.conf examples. You'll probably want to edit the port numbers to match your own configuration.

Example for a single host nginx config

Pros
This first snippet only requires a single host which makes testing via a mobile device on the same network easier
Cons
The referer (sic) checking for media routing is more complicated and may need updates from time to time.

Snippet:

http {
    ...

    # Change this to update where your fireplace is running.
    upstream fireplace {
        server localhost:8675;
    }

    # Change this to reflect where your zamboni is running.
    upstream zamboni {
        server localhost:8002;
    }

    # Change this to reflect where your webpay is running.
    # Optional - only needed if you're testing payments.
    upstream webpay {
        server localhost:9000;
    }

    server {

        # Listening on port 80 is nice but you have to start nginx
        # with the right permissions.
        listen       80 default;

        # Set a host name. You also have to alias this host to
        # 127.0.0.1 in /etc/hosts
        server_name  fireplace.local;

        location / {
            # Default to fireplace.
            proxy_pass http://fireplace;
            proxy_set_header Host $host;
        }

        location /mozpay/ {
            # This is an optional alias to your local Webpay server
            # so you can process payments. The /mozpay/ prefix is what we use in production.
            proxy_pass http://webpay;
            proxy_set_header Host $host;
        }

        # Conditionally pass Zamboni urls to Zamboni.
        location  ~ '^/(admin|addons|api|developers|jsi18n\.js|login|logout|lookup|reviewers|services|tmp)' {
            proxy_pass http://zamboni;
            proxy_set_header Host $host;
        }

        # Privacy policy etc are on zamboni.
        location /media/docs {
            proxy_pass http://zamboni;
            break;
        }

        # Conditionally handle /users for both Zamboni and Fireplace.
        location /users {
            proxy_set_header Host $host;
            if ($http_referer ~ '^http://[^/]*?/(developers|reviewers|login\?to=/(admin|reviewers|developers))') {
                proxy_pass http://zamboni;
                break;
            }
            proxy_pass http://fireplace;
        }

        # Conditionally handle media depending on where we are using referer (sic) header.
        location /media {
            proxy_set_header Host $host;
            if ($http_referer ~ '^http://[^/]*?/(admin|developers|login\?to=/(admin|reviewers|developers)|lookup|media/css/(ecosystem|devreg|gaia|mkt)|reviewers|services)') {
                proxy_pass http://zamboni;
                break;
            }
            if ($http_referer  ~ '^http://[^/]*?/mozpay') {
                proxy_pass http://webpay;
                break;
            }
            proxy_pass http://fireplace;
        }
    }
}

Alternative plan

Pros
Individual media config makes for a simpler config
Cons
Requires configuration of multiple hostnames to point at the development environment ip.

Alternatively, route your media to different hosts in each application. For example, in zamboni set:

MEDIA_URL = 'http://z.static.mozilla.dev/media/'

Alter /etc/hosts to route that to your machine:

127.0.0.1       z.static.mozilla.dev

Your nginx config becomes much simpler:

    server {
        server_name z.static.mozilla.dev;
        location / {
           root /Users/andy/sandboxes/zamboni/;
        }
    }

Rinse and repeat for webpay and so on. You can then remove referrer detection.

Clone this wiki locally