Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

send fails every other run. #86

Open
snuggs opened this issue Jul 11, 2017 · 0 comments
Open

send fails every other run. #86

snuggs opened this issue Jul 11, 2017 · 0 comments

Comments

@snuggs
Copy link

snuggs commented Jul 11, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant