Programmable Edge
Murahashi [Matt] Kenichi
Posted on March 8, 2019
10 years ago, we said "database access is too slow." We used cache layer, memcached.
5 years ago, we said "access to web server is too slow." We used CDN, application cache.
2 years ago, we said "appCache is not flexible." We used ServiceWorker.
Now, we said "Edge (CDN included) is not flexible."
Introduction of fly
This is from fly readme,
, this is edge, I want to create this by more programmable, and get more flexible.
Example 1
https://vanilla-terrier-972.edgeapp.net/
This is just proxy to https://www.moneyforward.vn .
This is getting-started from https://github.com/superfly/cdn#try-the-starter-app
import { backends, proxy, middleware, pipeline } from "@fly/cdn";
const mw = pipeline(
middleware.httpsUpgrader,
middleware.httpCache
)
const app = mw(
proxy("https://www.moneyforward.vn")
);
fly.http.respondWith(app);
I wrote this, and deployed to fly. I can create edge by easy way!
Example 2
Provided example
fly.http.respondWith(function(request){
return new Response("Hello! We support whirled peas.", { status: 200})
})
// if you'd prefer to be service worker compatibility, this is also supported:
// around addEventListener('fetch', function(event){})
Example 3
Provided example
addEventListener('fetch', function (event) {
event.respondWith(new Response('Redirecting',
{
headers: {
'Location': 'https://fly.io/docs/apps/'
},
status: 302
}
))
})
References
Posted on March 8, 2019
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
November 30, 2024