Yes, I did try this. I tried it in production and logged the requestId, both the Netlify edge function logs and locally show the same output.
Based on some testing, I have a different setup going.
/**
* x.js
*/
export default async (req, context) => {
const res = await context.next()
const data = await res.json()
const count = data.count + 1
console.log(count)
return Response.json({ count })
}
/**
* y.js
*/
export default async (req, context) => {
const res = await context.next()
const data = await res.json()
const count = data.count + 1
console.log(count)
return Response.json({ count })
}
/**
* z.js
*/
export default async (req, context) => {
const count = 1
console.log(count)
return Response.json({ count })
}
Output
[z] 1
[y] 2
[x] 3
Remove return from y.js
/**
* x.js
*/
export default async (req, context) => {
const res = await context.next()
const data = await res.json()
const count = data.count + 1
console.log(count)
return Response.json({ count })
}
/**
*y.js
*/
export default async (req, context) => {
const res = await context.next()
const data = await res.json()
const count = data.count + 1
console.log(count)
// return Response.json({ count })
}
/**
* z.js
*/
export default async (req, context) => {
const count = 1
console.log(count)
return Response.json({ count })
}
Output
[z] 1
[y] 2
[z] 1
[x] 2
Remove return from x.js
/**
* x.js
*/
export default async (req, context) => {
const res = await context.next()
const data = await res.json()
const count = data.count + 1
console.log(count)
// return Response.json({ count })
}
/**
* y.js
*/
export default async (req, context) => {
const res = await context.next()
const data = await res.json()
const count = data.count + 1
console.log(count)
return Response.json({ count })
}
/**
* z.js
*/
export default async (req, context) => {
const count = 1
console.log(count)
return Response.json({ count })
}
Output
[z] 1
[y] 2
[x] 3
[z] 1
[y] 2
In order to add a bit of context, I have included an additional console.log()
at the beginning of each function from the example before.
Removing return from y.js
/**
* x.js
*/
export default async (req, context) => {
console.log('x() invoked')
const res = await context.next()
const data = await res.json()
const count = data.count + 1
console.log(count)
return Response.json({ count })
}
/**
* y.js
*/
export default async (req, context) => {
console.log('y() invoked')
const res = await context.next()
const data = await res.json()
const count = data.count + 1
console.log(count)
// return Response.json({ count })
}
/**
* z.js
*/
export default async (req, context) => {
console.log('z() invoked')
const count = 1
console.log(count)
return Response.json({ count })
}
Output
[x] x() invoked
[y] y() invoked
[z] z() invoked
[z] 1
[y] 2
[z] z() invoked
[z] 1
[x] 2
Removing return from x.js
/**
* x.js
*/
export default async (req, context) => {
console.log('x() invoked')
const res = await context.next()
const data = await res.json()
const count = data.count + 1
console.log(count)
// return Response.json({ count })
}
/**
* y.js
*/
export default async (req, context) => {
console.log('y() invoked')
const res = await context.next()
const data = await res.json()
const count = data.count + 1
console.log(count)
return Response.json({ count })
}
/**
* z.js
*/
export default async (req, context) => {
console.log('z() invoked')
const count = 1
console.log(count)
return Response.json({ count })
}
Output
[x] x() invoked
[y] y() invoked
[z] z() invoked
[z] 1
[y] 2
[x] 3
[y] y() invoked
[z] z() invoked
[z] 1
[y] 2