如何在heroku上重定向后从axios检索请求



我使用重定向链接作为后端应用程序中每个用户的本地数据抓取方法。在我的本地机器上,它可以正常工作。axios的电话通了,它被重定向了,我收集了必要的信息。然而,在heroku上,在我部署的版本中,它只是崩溃并记录似乎是从调用重定向链接本身返回的对象,而不是被重定向的结果。

为了更清楚,我使用以下代码:

server.get('/displayGames', async (req, res) => {
const response = await axios.get('https://www.maxpreps.com/list/schedules_scores_redirect.aspx?gendersport=boys,football')
const html = response.data
const $ = cheerio.load(html)
$('.contest-box-item').find('.teams').each(function() {
const winner = $(this).find('.winner').find('.name').text()
const loser = $(this).find('[data-result="3"]').find('.name').text()
const winningScore = $(this).find('.winner').find('.score').text()
const losingScore = $(this).find('[data-result="3"]').find('.score').text()
const winningTeamLogo = $(this).find('.winner').find('.image').attr('data-lazy-image')
const losingTeamLogo = $(this).find('[data-result="3"]').find('.image').attr('data-lazy-image')
if (winner != '' && loser != '') {
displayGames.push({winner, loser, winningScore, losingScore, winningTeamLogo, losingTeamLogo})
displayGameModel.findOne({"winnerName":winner, "loserName":loser}, async (err, value) => {
if (!value) {
const newDisplayGame = new displayGameModel({"winnerName": winner, "winnerScore":winningScore, "winnerLogo":winningTeamLogo, "loserName": loser, "loserScore":losingScore, "loserLogo":losingTeamLogo})
await newDisplayGame.save()
}
})                         
}
})
res.json(displayGames)   
displayGames=[]
})

在我的本地机器上测试时,在访问端点时显示如下:

[
{
"winner": "Horseshoe Bend",
"loser": "Randolph County",
"winningScore": "54",
"losingScore": "10",
"winningTeamLogo": "https://image.maxpreps.io/school-mascot/7/8/6/786636ca-3e7f-48a6-b8c1-31b916fc2e06.gif?version=637698948600000000&width=30&height=30&fit=bounds",
"losingTeamLogo": "https://image.maxpreps.io/school-mascot/1/7/2/172e4833-fdc1-4148-9480-5f8a5acc474b.gif?version=637383408000000000&width=30&height=30&fit=bounds"
},
{
"winner": "Central of Clay County",
"loser": "Cleburne County",
"winningScore": "23",
"losingScore": "13",
"winningTeamLogo": "https://image.maxpreps.io/school-mascot/e/9/a/e9af196b-8f11-428b-9558-c30349d747ff.gif?version=637395749400000000&width=30&height=30&fit=bounds",
"losingTeamLogo": "https://image.maxpreps.io/school-mascot/7/4/0/7408877a-09da-42a7-a28c-7eff37a42ae7.gif?version=637701529200000000&width=30&height=30&fit=bounds"
},
{
"winner": "(#11) Graham-Kapowsin",
"loser": "(#12) Collins Hill",
"winningScore": "40",
"losingScore": "36",
"winningTeamLogo": "https://image.maxpreps.io/school-mascot/8/9/0/890e75ad-07a3-4e23-8244-b5de8578b14c.gif?version=635807519400000000&width=30&height=30&fit=bounds",
"losingTeamLogo": "https://image.maxpreps.io/school-mascot/9/c/5/9c5f1303-3f41-4319-aec9-6ce8dd6ebb76.gif?version=637856062800000000&width=30&height=30&fit=bounds"
},
{
"winner": "(#13) North Shore",
"loser": "(#21) Duncanville",
"winningScore": "17",
"losingScore": "10",
"winningTeamLogo": "https://image.maxpreps.io/school-mascot/0/b/c/0bcb98b4-30ea-4f0c-aaf5-c35f45870f53.gif?version=635379105600000000&width=30&height=30&fit=bounds",
"losingTeamLogo": "https://image.maxpreps.io/school-mascot/5/5/6/556cde7f-6469-4bd0-934c-fe78b5949f68.gif?version=637776592800000000&width=30&height=30&fit=bounds"
},
{
"winner": "(#8) Jesuit",
"loser": "Pine Forest",
"winningScore": "35",
"losingScore": "29",
"winningTeamLogo": "https://image.maxpreps.io/school-mascot/c/5/e/c5eec975-6440-4d2b-90b6-0f95f30e660f.gif?version=634632603600000000&width=30&height=30&fit=bounds",
"losingTeamLogo": "https://image.maxpreps.io/school-mascot/f/6/4/f64eb451-c381-42d0-afd0-7e4a0143f336.gif?version=636391719600000000&width=30&height=30&fit=bounds"
},
{
"winner": "(#2) Westlake",
"loser": "Guyer",
"winningScore": "40",
"losingScore": "21",
"winningTeamLogo": "https://image.maxpreps.io/school-mascot/0/0/1/001aabf6-309f-4083-9e31-074b68b97a81.gif?version=636688164000000000&width=30&height=30&fit=bounds",
"losingTeamLogo": "https://image.maxpreps.io/school-mascot/a/f/3/af3babf8-6b92-43ec-9d72-6a442b512c92.gif?version=635319439200000000&width=30&height=30&fit=bounds"
}
]

在我部署的版本上,它崩溃了,并在日志中返回以下内容:

2022-06-23T01:27:27.728093+00:00 app[web.1]: _newSessionPending: false,
2022-06-23T01:27:27.728093+00:00 app[web.1]: _controlReleased: true,
2022-06-23T01:27:27.728093+00:00 app[web.1]: secureConnecting: false,
2022-06-23T01:27:27.728093+00:00 app[web.1]: _SNICallback: null,
2022-06-23T01:27:27.728093+00:00 app[web.1]: servername: 'www.maxpreps.com',
2022-06-23T01:27:27.728094+00:00 app[web.1]: alpnProtocol: false,
2022-06-23T01:27:27.728094+00:00 app[web.1]: authorized: true,
2022-06-23T01:27:27.728094+00:00 app[web.1]: authorizationError: null,
2022-06-23T01:27:27.728094+00:00 app[web.1]: encrypted: true,
2022-06-23T01:27:27.728094+00:00 app[web.1]: _events: [Object: null prototype] {
2022-06-23T01:27:27.728095+00:00 app[web.1]: close: [Array],
2022-06-23T01:27:27.728095+00:00 app[web.1]: end: [Function: onReadableStreamEnd],
2022-06-23T01:27:27.728095+00:00 app[web.1]: newListener: [Function: keylogNewListener],
2022-06-23T01:27:27.728096+00:00 app[web.1]: secure: [Function: onConnectSecure],
2022-06-23T01:27:27.728096+00:00 app[web.1]: session: [Function (anonymous)],
2022-06-23T01:27:27.728096+00:00 app[web.1]: free: [Function: onFree],
2022-06-23T01:27:27.728096+00:00 app[web.1]: timeout: [Function: onTimeout],
2022-06-23T01:27:27.728096+00:00 app[web.1]: agentRemove: [Function: onRemove],
2022-06-23T01:27:27.728097+00:00 app[web.1]: error: [Function: socketErrorListener],
2022-06-23T01:27:27.728097+00:00 app[web.1]: finish: [Function]
2022-06-23T01:27:27.728097+00:00 app[web.1]: },
2022-06-23T01:27:27.728097+00:00 app[web.1]: _eventsCount: 10,
2022-06-23T01:27:27.728097+00:00 app[web.1]: connecting: false,
2022-06-23T01:27:27.728097+00:00 app[web.1]: _hadError: false,
2022-06-23T01:27:27.728098+00:00 app[web.1]: _parent: null,
2022-06-23T01:27:27.728098+00:00 app[web.1]: _host: 'www.maxpreps.com',
2022-06-23T01:27:27.728098+00:00 app[web.1]: _readableState: ReadableState {
2022-06-23T01:27:27.728098+00:00 app[web.1]: objectMode: false,
2022-06-23T01:27:27.728098+00:00 app[web.1]: highWaterMark: 16384,
2022-06-23T01:27:27.728099+00:00 app[web.1]: buffer: [BufferList],
2022-06-23T01:27:27.728099+00:00 app[web.1]: length: 0,
2022-06-23T01:27:27.728099+00:00 app[web.1]: pipes: [],
2022-06-23T01:27:27.728099+00:00 app[web.1]: flowing: true,
2022-06-23T01:27:27.728099+00:00 app[web.1]: ended: false,
2022-06-23T01:27:27.728100+00:00 app[web.1]: endEmitted: false,
2022-06-23T01:27:27.728100+00:00 app[web.1]: reading: true,
2022-06-23T01:27:27.728100+00:00 app[web.1]: constructed: true,
2022-06-23T01:27:27.728100+00:00 app[web.1]: sync: false,
2022-06-23T01:27:27.728100+00:00 app[web.1]: needReadable: true,
2022-06-23T01:27:27.728100+00:00 app[web.1]: emittedReadable: false,
2022-06-23T01:27:27.728101+00:00 app[web.1]: readableListening: false,
2022-06-23T01:27:27.728101+00:00 app[web.1]: resumeScheduled: false,
2022-06-23T01:27:27.728101+00:00 app[web.1]: errorEmitted: false,
2022-06-23T01:27:27.728101+00:00 app[web.1]: emitClose: false,
2022-06-23T01:27:27.728101+00:00 app[web.1]: autoDestroy: true,
2022-06-23T01:27:27.728101+00:00 app[web.1]: destroyed: false,
2022-06-23T01:27:27.728102+00:00 app[web.1]: errored: null,
2022-06-23T01:27:27.728102+00:00 app[web.1]: closed: false,
2022-06-23T01:27:27.728102+00:00 app[web.1]: closeEmitted: false,
2022-06-23T01:27:27.728102+00:00 app[web.1]: defaultEncoding: 'utf8',
2022-06-23T01:27:27.728102+00:00 app[web.1]: awaitDrainWriters: null,
2022-06-23T01:27:27.728103+00:00 app[web.1]: multiAwaitDrain: false,
2022-06-23T01:27:27.728103+00:00 app[web.1]: readingMore: false,
2022-06-23T01:27:27.728103+00:00 app[web.1]: dataEmitted: true,
2022-06-23T01:27:27.728103+00:00 app[web.1]: decoder: null,
2022-06-23T01:27:27.728103+00:00 app[web.1]: encoding: null,
2022-06-23T01:27:27.728104+00:00 app[web.1]: [Symbol(kPaused)]: false
2022-06-23T01:27:27.728104+00:00 app[web.1]: },
2022-06-23T01:27:27.728104+00:00 app[web.1]: _maxListeners: undefined,
2022-06-23T01:27:27.728104+00:00 app[web.1]: _writableState: WritableState {
2022-06-23T01:27:27.728104+00:00 app[web.1]: objectMode: false,
2022-06-23T01:27:27.728105+00:00 app[web.1]: highWaterMark: 16384,
2022-06-23T01:27:27.728105+00:00 app[web.1]: finalCalled: true,
2022-06-23T01:27:27.728105+00:00 app[web.1]: needDrain: false,
2022-06-23T01:27:27.728105+00:00 app[web.1]: ending: true,
2022-06-23T01:27:27.728105+00:00 app[web.1]: ended: true,
2022-06-23T01:27:27.728106+00:00 app[web.1]: finished: false,
2022-06-23T01:27:27.728106+00:00 app[web.1]: destroyed: false,
2022-06-23T01:27:27.728106+00:00 app[web.1]: decodeStrings: false,
2022-06-23T01:27:27.728106+00:00 app[web.1]: defaultEncoding: 'utf8',
2022-06-23T01:27:27.728106+00:00 app[web.1]: length: 0,
2022-06-23T01:27:27.728107+00:00 app[web.1]: writing: false,
2022-06-23T01:27:27.728107+00:00 app[web.1]: corked: 0,
2022-06-23T01:27:27.728107+00:00 app[web.1]: sync: false,
2022-06-23T01:27:27.728107+00:00 app[web.1]: bufferProcessing: false,
2022-06-23T01:27:27.728107+00:00 app[web.1]: onwrite: [Function: bound onwrite],
2022-06-23T01:27:27.728108+00:00 app[web.1]: writecb: null,
2022-06-23T01:27:27.728108+00:00 app[web.1]: writelen: 0,
2022-06-23T01:27:27.728109+00:00 app[web.1]: afterWriteTickInfo: null,
2022-06-23T01:27:27.728109+00:00 app[web.1]: buffered: [],
2022-06-23T01:27:27.728109+00:00 app[web.1]: bufferedIndex: 0,
2022-06-23T01:27:27.728109+00:00 app[web.1]: allBuffers: true,
2022-06-23T01:27:27.728109+00:00 app[web.1]: allNoop: true,
2022-06-23T01:27:27.728112+00:00 app[web.1]: pendingcb: 1,
2022-06-23T01:27:27.728113+00:00 app[web.1]: constructed: true,
2022-06-23T01:27:27.728113+00:00 app[web.1]: prefinished: false,
2022-06-23T01:27:27.728113+00:00 app[web.1]: errorEmitted: false,
2022-06-23T01:27:27.728113+00:00 app[web.1]: emitClose: false,
2022-06-23T01:27:27.728114+00:00 app[web.1]: autoDestroy: true,
2022-06-23T01:27:27.728114+00:00 app[web.1]: errored: null,
2022-06-23T01:27:27.728114+00:00 app[web.1]: closed: false,
2022-06-23T01:27:27.728114+00:00 app[web.1]: closeEmitted: false,
2022-06-23T01:27:27.728115+00:00 app[web.1]: [Symbol(kOnFinished)]: []
2022-06-23T01:27:27.728115+00:00 app[web.1]: },
2022-06-23T01:27:27.728115+00:00 app[web.1]: allowHalfOpen: false,
2022-06-23T01:27:27.728115+00:00 app[web.1]: _sockname
2022-06-23T01:27:27.728115+00:00 app[web.1]: Node.js v17.7.2
2022-06-23T01:27:27.738362+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=GET path="/displaygames" host=wcsn-backend.herokuapp.com request_id=0573a8cd-3a28-4d05-85e0-bd382749dc44 fwd="216.198.98.78" dyno=web.1 connect=0ms service=358ms status=503 bytes=0 protocol=https
2022-06-23T01:27:27.850704+00:00 heroku[web.1]: Process exited with status 1
2022-06-23T01:27:27.915043+00:00 heroku[web.1]: State changed from up to crashed

如何让我的代码在Heroku上工作?

我一直看到说使用HTTP而不是HTTPS的答案,这是你已经尝试过的东西吗?

https://stackoverflow.com/a/41489179/12826372