1
0
mirror of synced 2025-12-22 03:16:52 -05:00
Files
docs/middleware/fastly-behavior.js
brannon d575b8edd6 Update Fastly test middleware to run in staging ONLY.
Add ability to set more headers to mimic real content responses.
Add ability to inject errors, to help in validating behavior.
2022-06-02 17:19:53 -06:00

15 lines
584 B
JavaScript

// This middleware allows the client to cause the server-side processing to fail with a specific error.
// It is used for testing error handling with Fastly. It should only be enabled in non-production environments!
//
// NOTE: This middleware is intended to be removed once testing is complete!
//
export default function fastlyBehavior(req, res, next) {
if ((req.method === 'GET' || req.method === 'HEAD') && req.get('X-CacheTest-Error')) {
const error = parseInt(req.get('X-CacheTest-Error'))
res.status(error).send(`SIMULATED ERROR ${error}`)
return
}
next()
}