{"action":"created","issue":{"url":"https://api.github.com/repos/readium/readium-js-viewer/issues/336","labels_url":"https://api.github.com/repos/readium/readium-js-viewer/issues/336/labels{/name}","comments_url":"https://api.github.com/repos/readium/readium-js-viewer/issues/336/comments","events_url":"https://api.github.com/repos/readium/readium-js-viewer/issues/336/events","html_url":"https://github.com/readium/readium-js-viewer/issues/336","id":77549246,"number":336,"title":"Cloud reader: fetching + rendering EPUBs (zipped and expanded) hosted in separate HTTP domain","user":{"login":"danielweck","id":625201,"avatar_url":"https://avatars.githubusercontent.com/u/625201?v=3","gravatar_id":"","url":"https://api.github.com/users/danielweck","html_url":"https://github.com/danielweck","followers_url":"https://api.github.com/users/danielweck/followers","following_url":"https://api.github.com/users/danielweck/following{/other_user}","gists_url":"https://api.github.com/users/danielweck/gists{/gist_id}","starred_url":"https://api.github.com/users/danielweck/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danielweck/subscriptions","organizations_url":"https://api.github.com/users/danielweck/orgs","repos_url":"https://api.github.com/users/danielweck/repos","events_url":"https://api.github.com/users/danielweck/events{/privacy}","received_events_url":"https://api.github.com/users/danielweck/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/readium/readium-js-viewer/labels/enhancement","name":"enhancement","color":"bfe5bf"},{"url":"https://api.github.com/repos/readium/readium-js-viewer/labels/priority%20medium","name":"priority medium","color":"fbca04"},{"url":"https://api.github.com/repos/readium/readium-js-viewer/labels/ReadiumJS","name":"ReadiumJS","color":"fef2c0"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-05-18T08:00:29Z","updated_at":"2015-06-02T16:05:32Z","closed_at":"2015-06-02T16:05:32Z","body":"FYI, I managed to successfully configure HTTP CORS in my development environment, and this will be a built-in feature of the RequireJS refactoring (\"plugins\" feature branch).\r\n\r\nAs far as I can tell (minimal amount of testing), everything seems to work normally: completely transparent negotiation between the CORS-configured HTTP server and the (unmodified) XmlHttpRequests on Readium's client-side (some of which are wrapped in jQuery's convenient \"Ajax\" API, others ; like the ZIP library ; use the native API).\r\n\r\nBrowser usage example URLs:\r\n\r\n(zipped EPUB)\r\n`http://127.0.0.1/index.html?epub=http://192.168.1.64/epub_content/test.epub`\r\n\r\n(expanded EPUB)\r\n`http://127.0.0.1/index.html?epub=http://192.168.1.64/epub_content/moby_dick`\r\n\r\nI use this Node-based HTTP server as part of the build system for the cloud reader:\r\n\r\n`https://www.npmjs.com/package/http-server`\r\n\r\nThis one supports the HTTP 1.1 byte-range protocol (for media streaming and ZIP archive extracting) and CORS preflight, out of the box.\r\n\r\nCommand line usage:\r\n\r\n`http-server -p 80 --cors ./`\r\n\r\nI just had to modify the HTTP header configuration to meet our needs:\r\n\r\nhttps://github.com/indexzero/http-server/blob/master/lib/http-server.js#L46\r\n(see logged issue https://github.com/indexzero/http-server/issues/154 )\r\n\r\nBefore:\r\n```javascript\r\n  if (options.cors) {\r\n    this.headers['Access-Control-Allow-Origin'] = '*';\r\n    this.headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept';\r\n\r\n    before.push(corser.create());\r\n  }\r\n```\r\n\r\nAfter (larger-than-necessary whitelists, but never mind):\r\n```javascript\r\n  if (options.cors) {\r\n\r\nthis.headers[\"Access-Control-Allow-Methods\"] = \"GET, HEAD, POST\";\r\n\r\nthis.headers[\"Access-Control-Allow-Origin\"] = \"*\";\r\n\r\nthis.headers[\"Access-Control-Allow-Credentials\"] = \"true\";\r\n\r\nthis.headers[\"Access-Control-Allow-Headers\"] = \"Range, Content-Type, Origin, X-Requested-With, Accept, Accept-Language, Content-Language\";\r\n\r\nthis.headers[\"Access-Control-Expose-Headers\"] = \"Accept-Ranges, Content-Encoding, Content-Type, Content-Length, Content-Range, Content-Language, Cache-Control, Expires, Last-Modified, Pragma\";\r\n\r\n    before.push(corser.create());\r\n  }\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/readium/readium-js-viewer/issues/comments/108001755","html_url":"https://github.com/readium/readium-js-viewer/issues/336#issuecomment-108001755","issue_url":"https://api.github.com/repos/readium/readium-js-viewer/issues/336","id":108001755,"user":{"login":"danielweck","id":625201,"avatar_url":"https://avatars.githubusercontent.com/u/625201?v=3","gravatar_id":"","url":"https://api.github.com/users/danielweck","html_url":"https://github.com/danielweck","followers_url":"https://api.github.com/users/danielweck/followers","following_url":"https://api.github.com/users/danielweck/following{/other_user}","gists_url":"https://api.github.com/users/danielweck/gists{/gist_id}","starred_url":"https://api.github.com/users/danielweck/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danielweck/subscriptions","organizations_url":"https://api.github.com/users/danielweck/orgs","repos_url":"https://api.github.com/users/danielweck/repos","events_url":"https://api.github.com/users/danielweck/events{/privacy}","received_events_url":"https://api.github.com/users/danielweck/received_events","type":"User","site_admin":false},"created_at":"2015-06-02T16:05:32Z","updated_at":"2015-06-02T16:05:32Z","body":"Follow-up: https://docs.google.com/document/d/1RK_59-75OSE0PA6wexD9rYHQLnNYfoKIpsnH3SmDpUc\r\n\r\n"}}