add cf function
This commit is contained in:
parent
bfe7714311
commit
e470eb40c7
28
.drone.yml
28
.drone.yml
@ -1,15 +1,15 @@
|
||||
---
|
||||
kind: pipeline
|
||||
type: exec
|
||||
name: deploy
|
||||
|
||||
steps:
|
||||
|
||||
- name: rsync
|
||||
commands:
|
||||
- ./push.sh
|
||||
|
||||
when:
|
||||
branch: master
|
||||
event: push
|
||||
#---
|
||||
#kind: pipeline
|
||||
#type: exec
|
||||
#name: deploy
|
||||
#
|
||||
#steps:
|
||||
#
|
||||
#- name: rsync
|
||||
# commands:
|
||||
# - ./push.sh
|
||||
#
|
||||
# when:
|
||||
# branch: master
|
||||
# event: push
|
||||
|
@ -54,7 +54,7 @@ IP address tables
|
||||
|dn42-es-mad1.burble.dn42|172.20.129.170|fd42:4242:2601:2c::1|*Decommissioning - December 2021*|
|
||||
|us-phx1.burble.dn42 |172.20.129.171|fd42:4242:2601:2b::1|Private Node|
|
||||
|dn42-us-dal3.burble.dn42|172.20.129.172|fd42:4242:2601:2a::1|*Decommissioning - April 2022*|
|
||||
|*unassigned* |172.20.129.173|fd42:4242:2601:3b::1||
|
||||
|uk-lon3.burble.dn42 |172.20.129.173|fd42:4242:2601:27::1|Private Node|
|
||||
|dn42-ch-zur1.burble.dn42|172.20.129.174|fd42:4242:2601:28::1||
|
||||
|uk-lon4.burble.dn42 |172.20.129.175|fd42:4242:2601:29::1|Private Node|
|
||||
|*unassigned* |172.20.129.176|fd42:4242:2601:3d::1||
|
||||
@ -73,7 +73,6 @@ IP address tables
|
||||
|dn42-fr-rbx2.burble.dn42|172.20.129.189|fd42:4242:2601:26::1||
|
||||
|dn42-uk-bri1.burble.dn42|172.20.129.190|fd42:4242:2601:20::1|Private Node|
|
||||
| |172.20.129.191| |Reserved|
|
||||
|uk-lon3.burble.dn42| |fd42:4242:2601:27::1|Private Node|
|
||||
|
||||
## burble.dn42 Nodes (Public Addressing)
|
||||
|
||||
|
65
site/functions/roa/[path].js
Normal file
65
site/functions/roa/[path].js
Normal file
@ -0,0 +1,65 @@
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
export async function onRequest(context) {
|
||||
|
||||
// Contents of context object
|
||||
const {
|
||||
request, // same as existing Worker API
|
||||
env, // same as existing Worker API
|
||||
params, // if filename includes [id] or [[path]]
|
||||
waitUntil, // same as ctx.waitUntil in existing Worker API
|
||||
next, // used for middleware or to fetch assets
|
||||
data, // arbitrary space for passing data between middlewares
|
||||
} = context;
|
||||
|
||||
const url = new URL(request.url)
|
||||
|
||||
const key = new Request(url.toString(), request)
|
||||
const cache = caches.default
|
||||
|
||||
// is the page already cached ?
|
||||
let response = await cache.match(key)
|
||||
|
||||
if (!response) {
|
||||
// no, we must fetch from the explorer
|
||||
|
||||
const map={
|
||||
'dn42_roa_46.json': '/json',
|
||||
'dn42_roa_bird1_46.conf': '/bird/1/46',
|
||||
'dn42_roa_bird1_4.conf': '/bird/1/4',
|
||||
'dn42_roa_bird1_6.conf': '/bird/1/6',
|
||||
'dn42_roa_bird2_46.conf': '/bird/2/46',
|
||||
'dn42_roa_bird2_4.conf': '/bird/2/4',
|
||||
'dn42_roa_bird2_6.conf': '/bird/2/6',
|
||||
'dn42_roa_obgpd_4.conf': '/obgpd/4',
|
||||
'dn42_roa_obgpd_6.conf': '/obgpd/6',
|
||||
'dn42_roa_obgpd_46.conf': '/obgpd/46'
|
||||
}
|
||||
|
||||
const endpoint = map[url.pathname.split("/").pop()]
|
||||
if (!endpoint) {
|
||||
return new Response("404 Not Found", {
|
||||
'status': 404,
|
||||
'statusText': 'Not Found'
|
||||
})
|
||||
}
|
||||
|
||||
// fetch from the explorer
|
||||
const surl = 'https://explorer.burble.com/api/roa' + endpoint
|
||||
let sreq = new Request(surl, request)
|
||||
response = await fetch(sreq)
|
||||
response = new Response(response.body, response)
|
||||
|
||||
// set Cache-Control header
|
||||
response.headers.append("Cache-Control", "public,s-maxage=3600")
|
||||
|
||||
// and store in the cache
|
||||
waitUntil(cache.put(key, response.clone()))
|
||||
}
|
||||
|
||||
// finally, return the response back to the user
|
||||
return response
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// end of file
|
Loading…
x
Reference in New Issue
Block a user