@xdn/core

2.53.6 • Public • Published

Overview

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

The @xdn/core package provides a CDN-as-JavaScript API for defining edge routing and logic on the XDN.

Example Routes File

// routes.js

import { Router } from '@xdn/core/router'
import { createNextPlugin } = from '@xdn/next'
import { renderNextPage, nextRoutes } from '@xdn/next'

export default new Router()
  // redirect at edge
  .match('/some/path/:withVar', async ({ redirect }) => {
    redirect('/some/other/path/:withVar', { statusCode: 301 })
  })

  // proxy the legacy site
  .match('/some/path/:withVar', async ({ proxy }) => {
    proxy('legacy', {
      path: '/some/other/path/:withVar',
    })
  })

  // match based on header and proxy the legacy site
  .match({ headers: { 'xdn-device-type': /desktop/ } }, async ({ proxy }) => {
    proxy('legacy')
  })

  // vanity URL for next.js
  .match('/some/vanity/url/:productId', res => {
    renderNextPage('/p/[productId]', res)
  })

  // Send a synthetic html response
  .match('/static-html', ({ setResponseHeader, send }) => {
    setResponseHeader('Content-Type', 'text/html; charset=UTF-8')
    send('<html><body><h1>Hello world!</h1></body></html>', 200)
  })

  // match Next.js routes based on the pages directory
  .use(nextRoutes)

  // fall back to proxying the legacy site
  .fallback(({ proxy }) => proxy('legacy'))

Readme

Keywords

none

Package Sidebar

Install

npm i @xdn/core

Weekly Downloads

2

Version

2.53.6

License

UNLICENSED

Unpacked Size

677 kB

Total Files

203

Last publish

Collaborators

  • moovweb-admin