skevy / graphiql-app

Light, Electron-based Wrapper around GraphiQL
MIT License
2.95k stars 336 forks source link

Does not follow HTTP 301 redirects #156

Open bolinfest opened 4 years ago

bolinfest commented 4 years ago

I suspect this is because this uses Node's built-in http and https modules, which do not supports this. Perhaps the simplest thing is to use:

https://github.com/follow-redirects/follow-redirects

bolinfest commented 4 years ago

Incidentally, this was tricky to discover because the UI spins forever. In the developer console, there is an error message that starts with SyntaxError: Unexpected token < in JSON at position 0 at IncomingMessage because the content received starts with:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
bolinfest commented 4 years ago

I ran into a lot of problems while trying to build along the lines of what is described here:

https://github.com/fsevents/fsevents/issues/229

It would be helpful to specify in the build instructions what version(s) of node/npm this has been tested with.

bolinfest commented 4 years ago

I ended up creating a proxy in Python to automatically do the redirects:

#!/usr/bin/env python3

import subprocess
import http.server
import socketserver
import sys

PORT = 8000
URL = "http://1.3.3.7"  # Where the actual service lives

class MyHandler(http.server.BaseHTTPRequestHandler):
    def do_GET(self):
        url = URL + self.path
        sys.stderr.write(url + "\n")
        result = subprocess.run(["curl", "--location", url], stdout=subprocess.PIPE)
        if result.returncode == 0:
            self.send_response(200)
            self.send_header("Content-type", "text/json")
            self.end_headers()
            self.wfile.write(result.stdout)
        else:
            self.send_response(404)
            self.end_headers()
            sys.stderr(f"failed when accessing {url}: {result}")

def main():
    with socketserver.TCPServer(("", PORT), MyHandler) as httpd:
        print("serving at port", PORT)
        httpd.serve_forever()

if __name__ == "__main__":
    main()