Web application routing

Location path

Path in the build directory

/era_env/priv/sys_metadata/url_routes.json

Overview

Routing for HTTP requests to the web server.

Used in addition to the system web server descriptor, organizing automatic redirects and substitutions when accessing certain pages.

For example, a request to /scripteditor is redirected to /scripteditor/. That in turn substitutes the content of /scripteditor/index.html without redirection.

It is expected that url_routes.json will specify redirect and substitution pages for all system web applications included in the distribution.

Format:
[
  {
    "url": str,
    "type": "redirect" | "static" | "static_dir_with_404",
    "to": str,
    "code": int,
    "dir": str
  },
  ...
]
Table 1. Fields
Field Description

"url"

relative-root URL to be routed. Supports wildcard (*) to specify the remaining path.

"type"

routing mode:

  • "redirect" – returns an HTTP 3xx response; the specific code is specified in the "code" field;

  • "static" – serves the specific resource located at the URL in the "to" field;

  • "static_dir_with_404" – searches for the resource in the specified directory (the "dir" field) and serves it. If absent, serves the resource located at the URL in the "to" field. Used together with wildcard (*) in the "url" field.

"to"

new URL at which the resource is available.

"code"

(for type = redirect) HTTP response code with which redirection is performed.

"dir"

(for type = static_dir_with_404) directory in which an arbitrary resource is searched.

Example

Example:
[
  { "url": "/",          "type": "static",   "to": "/index.html" },
  { "url": "/login",     "type": "static",   "to": "/index.html" },

  { "url": "/doc",       "type": "redirect", "to": "/doc/", "code": 301 },
  { "url": "/doc/",      "type": "static",   "to": "/doc/index.html" },

  { "url": "/selector",  "type": "redirect", "to": "/selector/", "code": 301 },
  { "url": "/selector/", "type": "static",   "to": "/selector_dist/index.html" },
  {
    "url": "/selector/*",
    "type": "static_dir_with_404",
    "to": "/selector_dist/index.html",
    "dir": "/selector_dist/"
  },

  { "url": "/scripteditor",  "type": "redirect", "to": "/scripteditor/", "code": 301 },
  { "url": "/scripteditor/", "type": "static",   "to": "/scripteditor/index.html" },

  { "url": "/webphone",      "type": "redirect", "to": "/webphone/", "code": 301 },
  { "url": "/webphone/",     "type": "static",   "to": "/webphone/index.html" }
]