Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@fly/edge

superfly53Apache-2.00.10.0TypeScript support: included

Fly's TypeScript Edge

routing, adn, cdn, edge, flyio, onehostname, global, load-balancer, middleware

readme

Forking Edge

Fly Edge

npm version isc license Build Status Gitter

The Fly Edge project is a set of APIs for routing HTTP traffic, cache content, and add "middleware" (like auth) to any application. It's written in TypeScript and runs on the Fly Edge runtime. It's built for developers — that means runs locally, has a tests, and integrate into a CI/release pipeline.

The code targets the Service Worker API and uses the Fly runtime API where necessary. You can deploy it to fly.io hosting or run it on any platform with an Edge Service Worker implementation (with reduced features).

Getting Started

Pre-requisites

Try the starter app

git clone https://gist.github.com/ebc48856b74fde392a6d62a032b59a97.git forking-edge
cd forking-edge
yarn install
yarn start # visit http://localhost:3000

Once you have that running, try swapping in a different origin. Edit index.ts and and replace backends.origin("https://getting-started.edgeapp.net") with backends.githubPages("superfly/landing").

Deploy to production

You can deploy edge apps to the Fly hosting service using the CLI. Sign up at fly.io, then run:

yarn fly login
yarn fly app create <name-of-your-app>
yarn fly deploy

You can also run on CloudFlare or StackPath, though not all features will work.

Features

Straightforward TypeScript/ JavaScript API

You can do a lot with a single index.ts file. This example redirects all requests to https and caches content when possible:

import { backends, middleware, pipeline } from "@fly/edge";

// user middleware for https redirect and caching
const mw = pipeline(
  middleware.httpsUpgrader,
  middleware.httpCache
)

// point it at the origin
const app = mw(
  backends.origin("https://getting-started.edgeapp.net")
);

// respond to http requests
fly.http.respondWith(app);

Backends

Backends are origin services you can route requests to. The project includes a backend type any HTTP service, and more specialized types for proxying to third party services.

Want to help out? Write a new backend type and open a pull request!

Middleware

Middleware applies logic to requests before they're sent to the backend, and responses before they're sent to users.

Development

See CONTRIBUTING.

Configuration vs code

The Fly Edge can be run standalone with a yaml based configuration schema. If you prefer to run with a config file, check out the config README.

Who's using it?

  • cars.com: HTTP routing
  • glitch.com: custom domain routing
  • fontawesome.com: CDN for paid customers
  • distractify.com: routing, caching, redirect management
  • greenmatters.com: routing, caching, redirect management
  • artstorefronts.com: custom domain routing
  • kajabi.com: custom domain routing
  • posthaven.com: custom domain routing

changelog

Change Log

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

0.9.0-2 (2019-05-13)

0.9.0-1 (2019-05-13)

Bug Fixes

  • bad response on data API DELETE (3a91157)

0.9.0-0 (2019-05-09)

Features

  • data store REST API + write through cache (5a8ccf8)

0.8.0 (2019-04-10)

Features

  • allow tls options on proxy builder (c35213f)

0.7.2 (2019-04-04)

Bug Fixes

  • faster installs, fly now a dev dependency (d9e7e6b)

0.7.1 (2019-03-14)

Bug Fixes

  • proxy supports fetch client certificates (c8b56a4)

0.7.0 (2019-03-14)

Features

0.6.0 (2019-03-12)

0.6.0-0 (2019-02-20)

Bug Fixes

  • auto-webp works with config based setup now (a06b1cd)
  • conflicting fly versions in dev/dependencies (d0aa9c2)
  • getting started sending wrong host header (fixes: #34) (073bf67)
  • include aws dependencies (66ef0f5)
  • origin backend doesn't accept forwardHostHeader (6b97455)
  • origin backend respects forwardHostHeader option (57cd1d9)
  • origin backend users retries option properly (5d2242d)
  • proxy retries needs back off (3c305f5)
  • relative proxy import on s3 backend (#45) (5e01d86)
  • squareSpace -> squarespace (a60918b)

Features

0.5.0 (2019-01-17)

Features

0.4.0 (2019-01-09)

Features

Bug Fixes

  • generated typedefs break tsc compilation (0e21699)

0.4.0-1 (2019-01-09)

0.4.0-0 (2019-01-08)

0.3.3 (2018-12-18)

0.3.2 (2018-12-13)

Bug Fixes

0.3.1 (2018-12-13)

Bug Fixes

  • include proper files in publish (f6f30e7)

0.3.0 (2018-12-13)

Features

  • ghost pro backend type (dc1fca5)
  • GitHub Pages backend type (19e1a28)
  • Heroku backend support (a1d7edb)
  • package as an npm (b53cec1)
  • rewrite location headers on proxied responses (604a531)

0.2.0 (2018-10-20)

Features