Skip to content

Commit

Permalink
Support regular requests from clients other than apollo-upload-client…
Browse files Browse the repository at this point in the history
… again.

Fixes #4.
  • Loading branch information
jaydenseric committed Apr 5, 2017
1 parent 73c2a8b commit 7b1bcba
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,23 @@ export function processRequest (request, {uploadDir} = {}) {
})
}

export function apolloUploadKoa (options) {
return async function (ctx, next) {
// Skip if there are no uploads
if (ctx.request.is('multipart/form-data')) {
ctx.request.body = await processRequest(ctx.req, options)
}
await next()
}
}

export function apolloUploadExpress (options) {
return (request, response, next) => {
// Skip if there are no uploads
if (!request.is('multipart/form-data')) return next()
processRequest(request, options).then(body => {
request.body = body
next()
})
}
}

export function apolloUploadKoa (options) {
return async function (ctx, next) {
ctx.request.body = await processRequest(ctx.req, options)
await next()
}
}

0 comments on commit 7b1bcba

Please # to comment.