Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
178 views
in Technique[技术] by (71.8m points)

javascript - Unable to access/parse external webpage after deploying to heroku

My app is working as expected on localhost but when deployed to heroku, the external page I'm parsing is returning an access denied error.

This is the response of the external page on heroku (I cannot replicate it on local setup):

2021-01-26T23:16:37.537084+00:00 app[web.1]: [
2021-01-26T23:16:37.537127+00:00 app[web.1]:   '<HTML><HEAD>',
2021-01-26T23:16:37.537128+00:00 app[web.1]:   '<TITLE>Access Denied</TITLE>',
2021-01-26T23:16:37.537129+00:00 app[web.1]:   '</HEAD><BODY>',
2021-01-26T23:16:37.537129+00:00 app[web.1]:   '<H1>Access Denied</H1>',
2021-01-26T23:16:37.537129+00:00 app[web.1]:   ' ',
2021-01-26T23:16:37.537133+00:00 app[web.1]:   `You don't have permission to access "http&#58;&#47;&#47;www&#46;pcso&#46;gov&#46;ph&#47;SearchLottoResult&#46;aspx" on this server.<P>`,
2021-01-26T23:16:37.537140+00:00 app[web.1]:   'Reference&#32;&#35;18&#46;89112017&#46;1611702997&#46;802e1a8',
2021-01-26T23:16:37.537141+00:00 app[web.1]:   '</BODY>',
2021-01-26T23:16:37.537141+00:00 app[web.1]:   '</HTML>',
2021-01-26T23:16:37.537141+00:00 app[web.1]:   ''
2021-01-26T23:16:37.537142+00:00 app[web.1]: ]

I'm parsing the page using a callback method:

async function file_get_contents(uri, callback) {
    let res = await fetch(uri, { credentials: 'include' }),
        value = await res.text(); 
    return callback ? callback(value) : value;
}

I'm using the method like this:

const pages = (url, callback) => {
    file_get_contents(url)
    .then(res => {
        let page = res.replace(/+/gm, '').split('
')
        console.log(page)
    // other codes

URL is set like this:

app.get('/pages', async (req, res) => {
    await pages(`https://www.pcso.gov.ph/SearchLottoResult.aspx`, (err, data) => {
        if (err) {
            return response.send({
                err
            })
        }
        res.send(data)
    })
})

Is there a way to further debug this on heroku or replicate the issue on localhost? I'm using heroku local web to run the app but I still cannot reproduce the issue.

question from:https://stackoverflow.com/questions/65910915/unable-to-access-parse-external-webpage-after-deploying-to-heroku

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...