TEST SERVER

How can we help?

Proxies

Proxies instruct the edge servers to fetch content on behalf of the client. If you want to expose functionality on your origin server – or really any other server – you can do so with a proxy transparently to the client.

The proxies setting is an array of mappings, each of which consists of a regex and a replacement value.

Note: proxies have no ‘permanent’ option unlike redirects.

[
    {
        "regex": "/old/",
        "replacement": "/new/"
    }
]

In this example, all requests to /old/ are sent to /new/ with the response sent back to the client. The client sees this as a single request and never knows that the proxy is happening.

As the name suggests, regex accepts regular expressions.

[
    {
        "regex": "/old/(.*)/?$",
        "replacement": "/new/${1}/",
    }
]

For example, /old/my-page would be sent to /new/my-page/.

The response is proxied as-is with one caveat: text responses translate the origin hostname to the public hostname. This translation ensures that, for example, links in HTML work correctly and don’t inadvertently send the user to the origin server.

Example(s)

Sometimes you want a particular request to go directly to the origin server. For instance, maybe you want the /releases path of your site to proxy to the origin server so that the latest release is not accidentally cached. The public URL path exactly matches the one on the origin server so we use:

[
    {
        "regex": "^/releases/(.*)",
        "replacement": "/releases/${1}"
    }
]

Details

When an edge server receives a request to be proxied, it generates a new HTTP request to the destination indicated by replacement. The response of the new request is optionally translated – if it’s Content-Type starts with ‘text/’ – and then returned to the client.

You can determine if a request was proxied by the presence of the ‘x-mindspun-proxy’ HTTP header. The final destination of the proxied request is the value in ‘x-mindspun-origin-url’. These HTTP headers are particularly useful when debugging your proxy configuration.

Redirects differ from proxies in that they tell the client/browser where to get the new resource, instead of getting the resource on the clients behalf.