superfly / edge

A set of useful libraries for Edge Apps. Run locally, write tests, and integrate it into your deployment process. Move fast and maybe don't break things? Because, gosh darnit, you're an adult.
https://fly.io
Apache License 2.0
143 stars 10 forks source link

Add `mount` method #48

Open i8ramin opened 5 years ago

i8ramin commented 5 years ago

Allows you to mount routes to different proxied backends (supports RegExp)

Example:

 import { mount, MountInfo, proxy, middleware, pipeline } from '@fly/cdn'

 const routes: MountInfo[] = [
  ['/blog', proxy('https://medium.com/blog')],
  ['/docs', proxy('https://docs.example.com/docs')],
  [/^\/(?:[a-z]{2}(-[A-Z]{2})?\/)?app/, proxy('https://app.example.com')] // ie, /de-DE/products
 ]

 const p = pipeline(middleware.httpsUpgrader, middleware.autoWebp)
 const routerApp = p(mount(routes))

 fly.http.respondWith(routerApp)
i8ramin commented 5 years ago

Looks like the aws backend tests are failing for some reason. Unrelated to this change. https://dev.azure.com/flydotio/fly/_build/results?buildId=941

i8ramin commented 5 years ago

@KittyBot, @mrkurt any ideas?

i8ramin commented 5 years ago

Btw, this has happened before in another PR -- https://github.com/superfly/edge/pull/45#issuecomment-462967729