Firebase not adding CORS headers to REST requests












2















Is there a way to enable CORS for REST endpoints, as stated here and here? It looks like Firebase no longer adds them by default. It would be helpful for apps that don't need realtime connectivity or cant use websockets.



Here's a REST request to Firebase. If you check the response, there are no cors headers:
https://samplechat.firebaseio-demo.com/users/jack/name.json










share|improve this question





























    2















    Is there a way to enable CORS for REST endpoints, as stated here and here? It looks like Firebase no longer adds them by default. It would be helpful for apps that don't need realtime connectivity or cant use websockets.



    Here's a REST request to Firebase. If you check the response, there are no cors headers:
    https://samplechat.firebaseio-demo.com/users/jack/name.json










    share|improve this question



























      2












      2








      2








      Is there a way to enable CORS for REST endpoints, as stated here and here? It looks like Firebase no longer adds them by default. It would be helpful for apps that don't need realtime connectivity or cant use websockets.



      Here's a REST request to Firebase. If you check the response, there are no cors headers:
      https://samplechat.firebaseio-demo.com/users/jack/name.json










      share|improve this question
















      Is there a way to enable CORS for REST endpoints, as stated here and here? It looks like Firebase no longer adds them by default. It would be helpful for apps that don't need realtime connectivity or cant use websockets.



      Here's a REST request to Firebase. If you check the response, there are no cors headers:
      https://samplechat.firebaseio-demo.com/users/jack/name.json







      firebase






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited May 23 '17 at 12:09









      Community

      11




      11










      asked Dec 17 '15 at 17:36









      Andy MillerAndy Miller

      3841417




      3841417
























          1 Answer
          1






          active

          oldest

          votes


















          8














          Found the issue.



          All the REST endpoints need to end in '.json', including put and post requests. That triggers Firebase to set the cross-origin headers to the origin on the request. By not adding the '.json' to the end of my POST request, the origin headers were not added so it looked like a CORS issue.



          The example doesn't have a CORS header, so it looks like Firebase must add them only when needed.






          share|improve this answer
























          • Note that without .json, Firebase tries to load the developer console available at <your-project>.firebaseio.com.

            – Rob DiMarco
            Dec 17 '15 at 18:29






          • 1





            Out of curiosity, why are you using REST instead of the JS SDK?

            – David East
            Dec 17 '15 at 18:38






          • 1





            My app is primarily built for offline use, with only periodic syncs to the backend. I'd rather handle the offline state myself than set up websockets that constantly try to reconnect. I keep a parallel db in indexeddb where I keep track of offline modifications and then merge with online updates when the user goes back online.

            – Andy Miller
            Dec 17 '15 at 22:02











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f34340863%2ffirebase-not-adding-cors-headers-to-rest-requests%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          8














          Found the issue.



          All the REST endpoints need to end in '.json', including put and post requests. That triggers Firebase to set the cross-origin headers to the origin on the request. By not adding the '.json' to the end of my POST request, the origin headers were not added so it looked like a CORS issue.



          The example doesn't have a CORS header, so it looks like Firebase must add them only when needed.






          share|improve this answer
























          • Note that without .json, Firebase tries to load the developer console available at <your-project>.firebaseio.com.

            – Rob DiMarco
            Dec 17 '15 at 18:29






          • 1





            Out of curiosity, why are you using REST instead of the JS SDK?

            – David East
            Dec 17 '15 at 18:38






          • 1





            My app is primarily built for offline use, with only periodic syncs to the backend. I'd rather handle the offline state myself than set up websockets that constantly try to reconnect. I keep a parallel db in indexeddb where I keep track of offline modifications and then merge with online updates when the user goes back online.

            – Andy Miller
            Dec 17 '15 at 22:02
















          8














          Found the issue.



          All the REST endpoints need to end in '.json', including put and post requests. That triggers Firebase to set the cross-origin headers to the origin on the request. By not adding the '.json' to the end of my POST request, the origin headers were not added so it looked like a CORS issue.



          The example doesn't have a CORS header, so it looks like Firebase must add them only when needed.






          share|improve this answer
























          • Note that without .json, Firebase tries to load the developer console available at <your-project>.firebaseio.com.

            – Rob DiMarco
            Dec 17 '15 at 18:29






          • 1





            Out of curiosity, why are you using REST instead of the JS SDK?

            – David East
            Dec 17 '15 at 18:38






          • 1





            My app is primarily built for offline use, with only periodic syncs to the backend. I'd rather handle the offline state myself than set up websockets that constantly try to reconnect. I keep a parallel db in indexeddb where I keep track of offline modifications and then merge with online updates when the user goes back online.

            – Andy Miller
            Dec 17 '15 at 22:02














          8












          8








          8







          Found the issue.



          All the REST endpoints need to end in '.json', including put and post requests. That triggers Firebase to set the cross-origin headers to the origin on the request. By not adding the '.json' to the end of my POST request, the origin headers were not added so it looked like a CORS issue.



          The example doesn't have a CORS header, so it looks like Firebase must add them only when needed.






          share|improve this answer













          Found the issue.



          All the REST endpoints need to end in '.json', including put and post requests. That triggers Firebase to set the cross-origin headers to the origin on the request. By not adding the '.json' to the end of my POST request, the origin headers were not added so it looked like a CORS issue.



          The example doesn't have a CORS header, so it looks like Firebase must add them only when needed.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 17 '15 at 17:56









          Andy MillerAndy Miller

          3841417




          3841417













          • Note that without .json, Firebase tries to load the developer console available at <your-project>.firebaseio.com.

            – Rob DiMarco
            Dec 17 '15 at 18:29






          • 1





            Out of curiosity, why are you using REST instead of the JS SDK?

            – David East
            Dec 17 '15 at 18:38






          • 1





            My app is primarily built for offline use, with only periodic syncs to the backend. I'd rather handle the offline state myself than set up websockets that constantly try to reconnect. I keep a parallel db in indexeddb where I keep track of offline modifications and then merge with online updates when the user goes back online.

            – Andy Miller
            Dec 17 '15 at 22:02



















          • Note that without .json, Firebase tries to load the developer console available at <your-project>.firebaseio.com.

            – Rob DiMarco
            Dec 17 '15 at 18:29






          • 1





            Out of curiosity, why are you using REST instead of the JS SDK?

            – David East
            Dec 17 '15 at 18:38






          • 1





            My app is primarily built for offline use, with only periodic syncs to the backend. I'd rather handle the offline state myself than set up websockets that constantly try to reconnect. I keep a parallel db in indexeddb where I keep track of offline modifications and then merge with online updates when the user goes back online.

            – Andy Miller
            Dec 17 '15 at 22:02

















          Note that without .json, Firebase tries to load the developer console available at <your-project>.firebaseio.com.

          – Rob DiMarco
          Dec 17 '15 at 18:29





          Note that without .json, Firebase tries to load the developer console available at <your-project>.firebaseio.com.

          – Rob DiMarco
          Dec 17 '15 at 18:29




          1




          1





          Out of curiosity, why are you using REST instead of the JS SDK?

          – David East
          Dec 17 '15 at 18:38





          Out of curiosity, why are you using REST instead of the JS SDK?

          – David East
          Dec 17 '15 at 18:38




          1




          1





          My app is primarily built for offline use, with only periodic syncs to the backend. I'd rather handle the offline state myself than set up websockets that constantly try to reconnect. I keep a parallel db in indexeddb where I keep track of offline modifications and then merge with online updates when the user goes back online.

          – Andy Miller
          Dec 17 '15 at 22:02





          My app is primarily built for offline use, with only periodic syncs to the backend. I'd rather handle the offline state myself than set up websockets that constantly try to reconnect. I keep a parallel db in indexeddb where I keep track of offline modifications and then merge with online updates when the user goes back online.

          – Andy Miller
          Dec 17 '15 at 22:02




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f34340863%2ffirebase-not-adding-cors-headers-to-rest-requests%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Angular Downloading a file using contenturl with Basic Authentication

          Olmecas

          Can't read property showImagePicker of undefined in react native iOS