send fails every other run.
- Dominant language
- TypeScript
- Stars
- 433
- Forks
- 86
- PR merge metrics
- No merged PRs in 30d
Description
Appologize for the gif. However a gif is worth 1000 words. 😎
[The following code is running from snuggsi ツ](https://github.com/devpunks/snuggsi/blob/47af2f96ccc7ab7a0883c2e1a33fecbc24746268/mixins/middleware.es):
```javascript
const
root = 'mixins'
, mime = /^\*\/\*$/
, filter = /^\/mixins\/(.*\.es)*$/g
, send = require ('koa-send')
module.exports = async (context, next) => {
const
match = filter.test (context.path)
, resource = './storable.es'
, settings = [context, resource, { root }]
, header = ['Content-Type', 'application/ecmascript']
, response = match && await send ( ... settings )
void (response && context.set ( ... header ))
|| await next ()
console.log ('response', context.response, response)
}
```
By the way it's a little wonky to change headers AFTER send is called. (which just returns a file path anyways). Let me know where I can help. PR. etc.
Thanks in advance @tj

Contributor guide
Research direction
Reproduce the alternating failure using the middleware example in mixins/middleware.es, then inspect the filter.test(context.path) and koa-send interaction. Confirm the expected behavior for matching paths, file responses, and response headers, and add a regression test showing that repeated requests behave consistently.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100