MCPcopy Index your code
hub / github.com/serverless/serverless / handler

Function handler

packages/engine/src/lib/aws/cloudfrontRoutingFunction.js:9–33  ·  view source on GitHub ↗

* * Data in KV will be, * `name:routing` -> `{ "paths": { "/*": { "originId": "marzgentc-dev-alb-origin", "originType": "alb" } } }`

(event)

Source from the content-addressed store, hash-verified

7 */
8
9async function handler(event) {
10 // This is added at deploy time and is immutable after the function is created
11 const kvName = `marzgentc:routing`
12 // Get request details
13 var request = event.request
14 var uri = request.uri
15
16 // Try to find a matching route in the KV store
17 var routeData = null
18 try {
19 const kvsHandle = cf.kvs()
20 routeData = await kvsHandle.get(kvName, { format: 'json' })
21 } catch (e) {
22 // KV lookup failed, fallback to default
23 console.log('KV lookup error: ' + e.message)
24 }
25
26 if (routeData && routeData.paths) {
27 const matchingPath = findMatchingPath(uri, routeData.paths)
28 if (matchingPath) {
29 updateOrigin(request, routeData.paths[matchingPath])
30 }
31 }
32 return request
33}
34
35// Find the path pattern that matches the request URI
36function findMatchingPath(uri, paths) {

Callers 1

startControlServerFunction · 0.50

Calls 4

findMatchingPathFunction · 0.85
updateOriginFunction · 0.85
getMethod · 0.45
logMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…