marijnh / Eloquent-JavaScript

The sources for the Eloquent JavaScript book
https://eloquentjavascript.net
3.01k stars 793 forks source link

17.1 Content negotiation has minor issue #453

Closed dongyuwei closed 6 years ago

dongyuwei commented 6 years ago

hi @marijnh, 17.1 Content negotiation works if I visit it via HTTP: http://eloquentjavascript.net/2nd_edition/code/#17.1, but it does not work if I visit it via HTTPS: https://eloquentjavascript.net/2nd_edition/code/#17.1 because of the same domain origin policy limitation.

And the odd thing is I can't find the following code(demo code of 17.1 Content negotiation) in this project:

function requestAuthor(type) {
  var req = new XMLHttpRequest();
  req.open("GET", "http://eloquentjavascript.net/author", false);
  req.setRequestHeader("accept", type);
  req.send(null);
  return req.responseText;
}

var types = ["text/plain",
             "text/html",
             "application/json",
             "application/rainbows+unicorns"];

types.forEach(function(type) {
  try {
    console.log(type + ":\n", requestAuthor(type), "\n");
  } catch (e) {
    console.log("Raised error: " + e);
  }
});

I can find the related code in https://github.com/marijnh/Eloquent-JavaScript/blob/master/code/solutions/18_1_content_negotiation.js, so it seems this is a cache issue or some deploy issue. Can you keep an eye on this? Thank you.

marijnh commented 6 years ago

The 3rd edition uses https: URLs throughout, which sidesteps this issue. I think it's too minor to go back and fix in the 2nd edition.

And the odd thing is I can't find the following code(demo code of 17.1 Content negotiation) in this project:

Are you talking about the fact that the repository on github (which reflects the 3rd edition) has different code than the 2nd_edition/ URLs that you're looking at?

dongyuwei commented 6 years ago

Yes, there are different.