@edgio/core - v7.11.5

Overview

Core library for the Edgio, infrastructure to run your big, dynamic website frontend and make it load in less than one second.

The @edgio/core package provides API for defining edge routing and logic on Edgio.

Example Routes File

// routes.js

import { Router } from '@edgio/core/router'
import { createNextPlugin } = from '@edgio/next'
import { nextRoutes } from '@edgio/next'
import { SERVERLESS_ORIGIN_NAME } from '@edgio/core/origins'

export default new Router()
// fall back to proxying the legacy site, must be first as it will
// always match, and more specific matches will overwrite it later
.match("/:path*", {
origin: {
set_origin: 'legacy'
},
})

// match Next.js routes based on the pages directory
// Note: Next routes are internally setting a different fallback,
// this will effectively run both the above one and Next's one
.use(nextRoutes)

// redirect at edge
.match('/some/path/:withVar', {
url: {
url_redirect: {
destination: '/some/other/path/:withVar'
code: 301
}
}
})

// proxy the legacy site
.match('/some/path/:withVar', {
origin: {
set_origin: 'legacy'
},
url: {
url_rewrite: {
destination: '/some/other/path/:withVar'
}
}
})

// match based on header and proxy the legacy site
.match({ headers: { 'edgio-device-type': /desktop/ } }, {
origin: {
set_origin: 'legacy'
},
})

// vanity URL for next.js
.match('/some/vanity/url/:productId', {
headers: {
set_request_headers: {
'x-next-page': "index"
},
},
origin: {
set_origin: SERVERLESS_ORIGIN_NAME
}
})

// Send a synthetic html response
.match('/static-html', {
headers: {
set_request_headers: {
'Content-Type': "text/html; charset=UTF-8"
},
},
response: {
set_response_body: '<html><body><h1>Hello world!</h1></body></html>',
set_status_code: 200,
// Signal that we want early-exit, we don't want to propagate to other
// matches if if they could be matched
set_done: true,
}
})

Generated using TypeDoc