Git Product home page Git Product logo

cdn's Introduction

npm version isc license Build Status

Fly CDN

The Fly CDN is an edge application built to route HTTP traffic, cache content, and add "edge features" (like auth) to any application. It's written in TypeScript and runs on the Fly Edge Application runtime. It's built for developers โ€” it runs locally, has a test suite, and integrates 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).

Forking CDN

Getting Started

Pre-requisites

Try the starter app

git clone https://gist.github.com/ebc48856b74fde392a6d62a032b59a97.git forking-cdn
cd forking-cdn
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 CDN based applications 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/cdn";

// 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 CDN 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

cdn's People

Contributors

azure-pipelines[bot] avatar kittybot avatar michaeldwan avatar mrkurt avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.