Readonly
functionsVariable that is true only if router is inside of 'if' statement.
NOTE: we could allow user to 'else' and 'elseif' before previous 'if' calls, as in many cases, it would be valid - bool was added to avoid having to handle invalid cases.
Invalid cases :
Also, it just seems wrong to allow calling something like .get().elseif()
Readonly
preloadStatic
functionDefines a route that matches all requests.
A self reference, suitable for chaining
Features to apply on all requests.
Optional
options: RouteOptionsAdds a route that matches all requests that result in an error.
Example:
new Router()
.catch(/^(4|5)\d{2}$/, {
// retry all 4xx and 5xx errors using the legacy origin
retry: {
origin: "legacy",
},
});
A self-reference, suitable for chaining.
A regular expression, string or number that matches the status code returned by the origin
Features to apply when a request matches the route
Defines a route that matches DELETE requests.
A self reference, suitable for chaining
An express-style path expression, regular expression or advanced criteria object
Features to apply when a request matches the route
Optional
options: RouteOptionsAdds an else condition - requires either 'if' or 'elseif' functions to be called previously.
A self reference, suitable for chaining
Rest
...featuresOrRouters: ConditionFeaturesParam[]additional features to be applied, or routers to be nested.
Adds an elseif condition - requires either 'if' or 'elseif' functions to be called previously.
A self reference, suitable for chaining
A criteria object, with ability to create advanced criteria through 'and' and 'or' methods.
Rest
...featuresOrRouters: ConditionFeaturesParam[]additional features to be applied, or routers to be nested.
Forces the HTTPS protocol for all requests by redirecting HTTP requests to HTTPS
and sets the Strict-Transport-Security
header with the specified options
to tell the browser to remember that this site is only to be accessed using HTTPS.
Example:
new Router()
.forceHttps({
redirectCode: 302,
hsts: true,
hstsMaxAge: 31536000,
})
.get('/api/products/:category/:id', ({ setOrigin }) => {
setOrigin('api');
})
A self-reference, suitable for chaining.
Defines a route that matches GET requests.
A self reference, suitable for chaining
An express-style path expression, regular expression or advanced criteria object
Features to apply when a request matches the route.
Optional
options: RouteOptionsReturns the static asset manifest from this router file. NOTE: This method is needed because we're dynamically loading another Router class from a bundled routes.js file, which doesn't share a same class static variables.
Defines a route that matches HEAD requests.
A self reference, suitable for chaining
An express-style path expression, regular expression or advanced criteria object
Features to apply when a request matches the route
Optional
options: RouteOptionsAdds an if condition
A self reference, suitable for chaining
A criteria object, with ability to create advanced criteria through 'and' and 'or' methods.
Rest
...featuresOrRouters: ConditionFeaturesParam[]additional features to be applied, or routers to be nested.
Defines a route.
A self reference, suitable for chaining
An express-style path expression, regular expression or advanced criteria object
Features to apply when a request matches the route
Optional
options: RouteOptionsDisables crawling of permalinks by setting the x-robots-tag: noindex
response header
for hosts matching edgio.link or edgio-perma.link.
new Router().noIndexPermalink()
Deprecated. Indexing permalinks is automatically disabled. Use indexPermalink?: boolean
on Router Options to enable them.
*
A self-reference, suitable for chaining.
Defines a route that matches OPTIONS requests.
A self reference, suitable for chaining
An express-style path expression, regular expression or advanced criteria object
Features to apply when a request matches the route
Optional
options: RouteOptionsDefines a route that matches PATCH requests.
A self reference, suitable for chaining
An express-style path expression, regular expression or advanced criteria object
Features to apply when a request matches the route
Optional
options: RouteOptionsDefines a route that matches POST requests.
A self reference, suitable for chaining
An express-style path expression, regular expression or advanced criteria object
Features to apply when a request matches the route
Optional
options: RouteOptionsDefines a route that matches POST requests.
A self reference, suitable for chaining
An express-style path expression, regular expression or advanced criteria object
Features to apply when a request matches the route
Optional
options: RouteOptionsAdds routes for all static assets in a directory tree.
A self-reference, suitable for chaining.
The path to a directory containing static assets relative to the root of your project.
Registers a plugin that adds group of rules into the router. This method should be always called before any other methods that add rules. Example
import { Router } = from '@edgio/core/router'
import { nextRoutes } from '@edgio/next'
export default new Router()
// NextRoutes automatically adds rules for all Next.js pages and their assets.
// This should be called before any custom rules are added.
.use(nextRoutes)
.get('/custom-rule', {
origin: {
set_origin: "api"
}
})
Static
collectStatic
loadGenerated using TypeDoc
The router allows to define EdgeJS rules and their associated features in convenient way as a chainable javascript code. Please pay attention to the following notes when using Router to avoid unexpected behavior.
Router evaluation
The defined EdgeJS rules are transformed to equivalent EdgeControl rules for the Edge only once during the build of Router when it's evaluated in Edgio's serverless cloud. Therefore, any other runtime modifications of the Router are not supported even though they are valid javascript code.
Example of incorrect usages: