Fastly
Fastly [email protected] installation instructions.
Edgemesh Client to a Fastly Compute at Edge enabled site is super easy. To start, add the following line as early as possible to the <head> tag of your index.html:
index.html
<script
async
type="application/javascript"
data-cfasync="false"
src="https://static.edgeme.sh/client.js">
</script>
You can pass any of the Client Config options to the Edgemesh class constructor:
index.html
<script type="application/javascript">
EDGEMESH = {
swUrl: '/my-sw.js',
scope: '/assets'
}
</script>
<script
async
type="application/javascript"
data-cfasync="false"
src="https://static.edgeme.sh/client.js"
onload="window.edgemesh = new Edgemesh({
swUrl: '/my-sw.js',
scope: '/assets'
})">
<script/>
Next up, just enable a Compute at Edge worker to listen for the Edgemesh Service worker path and return the code. A functional example is show below:
import { Request, Response, URL, Fastly, Headers } from '@fastly/as-compute'
const backend = 'your-backend'
const text = "importScripts('https://static.edgeme.sh/edgemesh-sw.js')"
function fetch (request: Request): Response {
const url = new URL(request.url)
if (request.method === 'GET' && url.pathname === '/sw.js') {
const headers = new Headers()
headers.set('Content-Type', 'application/javascript')
return new Response(String.UTF8.encode(text), {
url: url.toString(),
status: 200,
headers
})
}
const cacheOverride = new Fastly.CacheOverride()
// Set your default cache settings here
// cacheOverride.setSWR(60 * 60 * 24)
return Fastly.fetch(request, { backend, cacheOverride }).wait()
}
Fastly.respondWith(fetch(Fastly.getClientRequest()))typ
Lastly, create an account on the Edgemesh Portal to validate the installation. Data should begin flowing into the system within 15 minutes!
Copy link