forwardemail / forwardemail/superagent

Cannot read property 'request' of undefined

Open
#1,592 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
16.6k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

while I request a file from a server in koa
```javascript
router.post('/proxy', async function (ctx) {
let postParam = ctx.request.body;
let fileName = urlencode.decode(postParam.fileName);
let filePath = urlencode.decode(postParam.filePath);
filePaths = filePath.split('/');
filePaths = filePaths.slice(0,-1);
filePath = filePaths.join('/') + '/' + postParam.fileName;
console.log('filePath: ', filePath)

let res = superagent.get(postParam.filePath);
let passThroughtStream = new stream.PassThrough();
res.pipe(passThroughtStream);

ctx.set("Content-disposition", "attachment; filename=" + postParam.fileName);
ctx.type = filePath.split('.')[1];
ctx.body = passThroughtStream;
});
```
superagent makes error:
```javascript
TypeError: Cannot read property 'request' of undefined
at Request.request (/Users/mengff/Documents/workspace/github/download-demo/node_modules/_superagent@6.1.0@superagent/lib/node/index.js:795:18)
at Request.end (/Users/mengff/Documents/workspace/github/download-demo/node_modules/_superagent@6.1.0@superagent/lib/node/index.js:951:8)
at Request.pipe (/Users/mengff/Documents/workspace/github/download-demo/node_modules/_superagent@6.1.0@superagent/lib/node/index.js:434:8)
at /Users/mengff/Documents/workspace/github/download-demo/index.js:66:9
at dispatch (/Users/mengff/Documents/workspace/github/download-demo/node_modules/_koa-compose@4.1.0@koa-compose/index.js:42:32)
at /Users/mengff/Documents/workspace/github/download-demo/node_modules/_koa-router@9.4.0@koa-router/lib/router.js:372:16
at dispatch (/Users/mengff/Documents/workspace/github/download-demo/node_modules/_koa-compose@4.1.0@koa-compose/index.js:42:32)
at /Users/mengff/Documents/workspace/github/download-demo/node_modules/_koa-compose@4.1.0@koa-compose/index.js:34:12
at dispatch (/Users/mengff/Documents/workspace/github/download-demo/node_modules/_koa-router@9.4.0@koa-router/lib/router.js:377:31)
at dispatch (/Users/mengff/Documents/workspace/github/download-demo/node_modules/_koa-compose@4.1.0@koa-compose/index.js:42:32)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.