Skip to content

Commit

Permalink
return 404 if we have too many redirects on heroku
Browse files Browse the repository at this point in the history
  • Loading branch information
netptop committed Mar 14, 2020
1 parent 2c79057 commit 777b974
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ let cookieDomainRewrite = serverName
let proxy = Proxy({ urlModify, httpprefix, serverName, port, cookieDomainRewrite, locationReplaceMap302, regReplaceMap, siteSpecificReplace, pathReplace})

const middle1 = (req, res, next) => {
console.log(`==== req.url:${req.url}, req headers:${JSON.stringify(req.headers)}`)
console.log(`req.url:${req.url}`)
const dirPath = path.join(__dirname, req.url)
let fwdStr = req.headers['x-forwarded-for']
if (fwdStr && fwdStr.split(',').length > 3) { // too many forwardings
return res.status(404).send('{"error": "too many redirects"}')
}
if (req.url === '/' || req.url === '/index.html') {
body = fs.readFileSync(path.join(__dirname, './index.html'), encoding = 'utf-8')
res.status(200).send(body)
Expand Down
11 changes: 11 additions & 0 deletions test/siteproxylocal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,14 @@ test('youtube homepage issue', async () => {
// console.log(`${response.data}`)
expect(response.data.indexOf(`"\\/service_ajax\\",`)).toBe(-1)
}, 3000); // should be done within 3 seconds.

// heroku headers:
// h==== req.url:/https/id.google.com/verify/ALoz5hxFM5vKCyL4RFaFnt6WR_AuQbx7abPPVMjTqOcXGhuzO-IkSXVdsRZsYnmhe8kQSMl9uvqudUdIQBA07Fg_guEQ7c0GP6qrAPVQrScGetd8fAZfMhk, req
// hheaders:{"host":"siteproxy.herokuapp.com","connection":"close","sec-fetch-dest":"image","dpr":"1","user-agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/5
// h37.36","accept":"image/webp,image/apng,image/*,*/*;q=0.8","sec-fetch-site":"same-origin","sec-fetch-mode":"no-cors","referer":"https://siteproxy.herokuapp.com/","accept-encoding":"gzip, deflate, br","accept-lang
// huage":"en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7","cookie":"NID=200=oRA6eiHr-AVq3TYpu1hAYlFFTt4FE3NTwVGhDTjs1L16VjJEuuyKW33tdEvz9ibbZNBplYLxm53p0O5AxgwyqCO1dzXie7NB_Mjq9B4AJyaZPMHKVaF0dqES1qtvyz7pRj5BqA6EKb7QB3FzLmj96
// hR4aggHdBTbu6yZWnZmvc10; 1P_JAR=2020-03-13-23","x-request-id":"d2e7fa06-ed41-4a49-b92d-7a5f87e5feb3","x-forwarded-for":"135.0.54.232","x-forwarded-proto":"https","x-forwarded-port":"443","via":"1.1 vegur","connec
// ht-time":"0","x-request-start":"1584141848398","total-route-time":"0"}
// h2020-03-13T23:24:08.403097+00:00 app[web.1]: httpType:https, host:id.google.com


0 comments on commit 777b974

Please sign in to comment.