DrKylstein / retro-proxy

A https to http proxy that allow old browsers to access modern sites, with conversion and compression options.
BSD 3-Clause "New" or "Revised" License
108 stars 5 forks source link

Crash on 404 #5

Closed BjornB2 closed 8 months ago

BjornB2 commented 8 months ago

Hey! I've been playing around with my Psion 5mx to get it connected, and also found your proxy which is really awesome. I'd like to add it to my instructions since it can be run on the same raspberry pi that I use to connect to the internet in the first place. It's a bit slow on a Raspberry Pi 3B but let's say that that is part of the retro experience 😉

The only issue I run into is that if I enter a non-existing website, the proxy crashes.

me@MacBook-Air-van-Bjorn retro-proxy % yarn start
yarn run v1.22.21
$ node ./
allow-list [
  'kdelaney.neocities.org',
  'sgi.neocities.org',
  'web.archive.org',
  'toastytech.com',
  'www.theoldrobots.com',
  'retro.hackaday.com',
  'sgi.neocities.org'
]
Listening on port 3000, CSS is disabled, images are compressed

/Users/me/retro-proxy/retro-proxy/node_modules/node-fetch/lib/index.js:1461
            reject(new FetchError(`request to ${request.url} failed, reason: ${err.message}`, 'system', err));
                   ^
FetchError: request to http://gittttthub.org/ failed, reason: getaddrinfo ENOTFOUND gittttthub.org
    at ClientRequest.<anonymous> (/Users/me/retro-proxy/retro-proxy/node_modules/node-fetch/lib/index.js:1461:11)
    at ClientRequest.emit (node:events:519:28)
    at Socket.socketErrorListener (node:_http_client:495:9)
    at Socket.emit (node:events:519:28)
    at emitErrorNT (node:internal/streams/destroy:169:8)
    at emitErrorCloseNT (node:internal/streams/destroy:128:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  type: 'system',
  errno: 'ENOTFOUND',
  code: 'ENOTFOUND'
}

Node.js v21.5.0
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Is this an easy fix maybe?

Also, I've tried to find out how to run this as a service or something, but couldn't find if that works with yarn start. Not a linux expert so to say :)

DrKylstein commented 8 months ago

I have just pushed a fix to send a 502 error page when the fetch fails instead of crashing.

Technically, a 404 is received when the site was found, but the page was not. That worked already. In this case, the site itself was not found, which is a different kind of error that was not being handled.