Skip to content

index.json Reference

mattbasta edited this page Oct 23, 2010 · 4 revisions

The index.json file is a JSON-format file that contains the rules that Interchange follows when routing inbound requests.

The root structure of the file should be a list: []. The child elements of the root should be elements that match the following format:

{
	"domain":"example.com",
	"policies":[]
}

The object should contain a “domain” element. When a URL is captured by Interchange for routing, these child elements are tested one-by-one until a matching domain has been found. When it has been found, the process is repeated on the elements of the “policies” element. If there are no matches in the policies element, the rest of the domain elements are tested.

The elements that are contained in the policies element are known as policy elements. These elements are re-used in any other scenario where policy elements are called for.

Policy Elements

Subdomain

{
	"type":"subdomain",
	"domain":"abc",
	"policies":[]
}

The “domain” element of this node contains the subdomain name. Only one subdomain can be matched at any given time. To match nested subdomains, another subdomain element should be nested within the “policies” element.

Folder

{
	"type":"folder",
	"folder":"images",
	"policies":[]
}

This element behaves identically to the Subdomain policy element, though instead of matching subdomains, it matches subdirectories of the current path.

Error

{
	"type":"error",
	"http":404,
	"page":"pages/missing.html"
}

When Interchange encounters an Error element, it returns the HTTP error code supplied by the “http” element. If the “page” element is specified, the file specified by it will be read out to the client in addition to the error’s HTTP header. If the error code specified is not recognized, Interchange defaults to a 404 error. The recognized status codes can be found in http_codes.php.

Redirect

{
	"type":"redirect",
	"href":"http://wherever/you/want/to/go",
	"http":301
}

Similar to the Error element, this policy element redirects the client to the URL specified by the “href” element. If the “http” element is provided, that HTTP status code will be returned. The recognized status codes can also be found in http_codes.php.

Lib

{
	"type":"lib",
	"library":"html"
}

Lib policy elements load up library code when an App policy element has been encountered. The “library” element contains the name of the PHP file to be included (from the /libraries directory). It should not include the “.php” extension. It may include subdirectories. In the example above, the /libraries/html.php file is loaded. Libraries are loaded in the order that Lib elements are encountered.

Note: As mentioned above, Lib elements do not load their associated libraries when the element is encountered, but rather when an App element has been encountered. This prevents libraries from being unnecessarily loaded.

App

{
	"type":"app",
	"endpoint":"static/images"
}

An App policy element begins execution of an application endpoint. When an App element has been encountered, Interchange stops executing the remainder of the index.json file.

The “endpoint” element contains the name of the path of the directory containing the endpoint code. The example above, for instance, would load the endpoint found within /endpoints/static/images/.

Methods

Similar to an App policy element, a Methods element defines a special type of endpoint that is accessed not procedurally (as a standard endpoint is), but rather is loaded and accessed based on information provided in the URL.

{
	"type":"methods",
	"endpoint":"foo/bar"
}

The Methods element behaves identically to the App element. It halts the parsing on the index.json file and begins processing the application.

The endpoint interface for a Methods element is quite different, however, from an App element in that it can be used to serve both dynamic as well as static content. This is explained more thoroughly in Methodical Endpoints.

Clone this wiki locally