-
-
Notifications
You must be signed in to change notification settings - Fork 225
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
Overriding port for absolute refs when run from browser [3.1.2] #29
Comments
There's nothing in JSON Schema $Ref Parser that would add port 3000 to URLs. You can verify this yourself by checking the URL at this point in the code to see the HTTP request that is being sent. Perhaps the server you're using is doing some redirect or proxying behavior? |
I've done some debugging and I think there's a bug here. This script is running on a page served from localhost:3000 wherein I want to parser.dereference('http:https://localhost/schema/01/plantdb.json') quick sidenote: A simple fix here is appending :80 to the hostname, but then the bug just moves to the request for each ref URL within (which don't have port numbers, assuming the sensible default of 80 for http) which I ordinarily wouldn't have control over, so I'm keeping it simple here by leaving the port off the initial request This URL gets parsed to the following object as a function parameter to {
"protocol":"http:",
"slashes":true,
"auth":null,
"host":"localhost",
"port":null,
"hostname":"localhost",
"hash":null,
"search":null,
"query":null,
"pathname":"/schema/01/plantdb.json",
"path":"/schema/01/plantdb.json",
"href":"http:https://localhost/schema/01/plantdb.json"
} Note that This is then used to create a new options object for var req = protocol.get({
hostname: localhost,
port: null,
path: "/schema/01/plantdb.json",
auth: null,
headers: {},
withCredentials: false
}); In the browser, the This is where the bug appears.
if (!params.host && !params.port) {
params.port = parseInt(window.location.port, 10);
}
if (!params.host && params.hostname) {
params.host = params.hostname;
} I'm not sure whether this should be considered a bug in According to the Node docs for
According to
Whatever the case, if I could submit a pull request if you agree. |
@andru - Wow, thanks for the thorough explanation! I like your idea of setting both Whenever I get a chance, I plan to resume working on JSON Schema $Ref Parser v4.0, and one of the changes that I plan to make is getting rid of HTTP-Browserify, probably in favor of Axios or something |
PR was requested in 2016 but never received, so have to assume this either works now or demand is not large. |
I've got a schema with absolute urls to resources with no port number in the URL...
(greatly simplified for clarity)
and I'm loading this on the client from an app hosted at
localhost:3000
. Trying to dereference a schema file hosted on the same hostname, but without specifying a port number...actually tries to load the schema from
http:https://localhost:3000/schema/01/plantdb.json
and fails with an invalid schema error. If I explicitly add the port number to the schema URL:then that schema file loads, but all refs within are still loaded from port
http:https://localhost:3000
.Is this a bug, or is there a config somewhere I'm missing to force the port number on ref requests?
The text was updated successfully, but these errors were encountered: