graphiql-app icon indicating copy to clipboard operation
graphiql-app copied to clipboard

Does not follow HTTP 301 redirects

Open bolinfest opened this issue 5 years ago • 3 comments

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 avatar Oct 02 '19 04:10 bolinfest

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 avatar Oct 02 '19 04:10 bolinfest

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 avatar Oct 02 '19 04:10 bolinfest

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()

bolinfest avatar Oct 02 '19 05:10 bolinfest