Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not follow HTTP 301 redirects #156

Open
bolinfest opened this issue Oct 2, 2019 · 3 comments
Open

Does not follow HTTP 301 redirects #156

bolinfest opened this issue Oct 2, 2019 · 3 comments

Comments

@bolinfest
Copy link

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
Copy link
Author

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
Copy link
Author

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

fsevents/fsevents#229

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

@bolinfest
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant