send icon indicating copy to clipboard operation
send copied to clipboard

send fails every other run.

Open snuggs opened this issue 8 years ago • 0 comments

Appologize for the gif. However a gif is worth 1000 words. 😎

The following code is running from snuggsi ツ:

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 koa

snuggs avatar Jul 11 '17 22:07 snuggs