Add ability to set more headers to mimic real content responses. Add ability to inject errors, to help in validating behavior.
15 lines
584 B
JavaScript
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()
|
|
}
|