MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    Weather module - creating new Provider

    Scheduled Pinned Locked Moved Troubleshooting
    7 Posts 3 Posters 1.5k Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A Offline
      ashishtank Module Developer @crazylegs
      last edited by

      @crazylegs This are CORS errors, it means that weather site of Canada can not be accessed via origin localhost:8080. This only occurs from browser. If you request this from Node helper it should not occur as server clients (non browser) do not check for pre flight requests. When you open it in browser it is not a api request but just GET but when you try to access it via JavaScript code it first do preflight request (OPTIONS verb) to check if you are allowed or not.

      Right now weather module does the request from browser and not from node helper so this issue occurs.

      f5820d64-41d0-479e-b5d2-79b3f6185d36-image.png

      possible solution is that you create a proxy api and call Canada weather api from that api and use proxy api here (which should allow CORS).

      1 Reply Last reply Reply Quote 0
      • crazylegsC Offline
        crazylegs
        last edited by

        Thank you so much for the feedback - very much appreciated!

        Your explanation makes a lot of sense and confirms (more clearly) what I’ve been reading in other places. I’ll think a bit about my options, including configuring a proxy to sit in front of the Environment Canada api or even just creating my own module that implements node_helper (although I’d prefer to leverage weather).

        1 Reply Last reply Reply Quote 0
        • A Offline
          ashishtank Module Developer
          last edited by

          @crazylegs : would be a good idea to add node_helper in weather module and allow to have configurable option for weather provider to get the data via node helper proxy. Current code will not change much and current providers can also leverage this. If you are going to do this open an issue on GitHub and propose solution or make a pull request.

          crazylegsC 1 Reply Last reply Reply Quote 0
          • crazylegsC Offline
            crazylegs @ashishtank
            last edited by

            @ashishtank Yes I agree 100%. The optimal solution is likely to push at least some of the fetchData instance function’s responsibility into node_helper. Assuming this can be done without breaking Promise functionality, it should be invisible to current Providers. I’m going to play around with this a bit and then raise an appropriate request on github. Thanks again for your feedback and guidance!

            1 Reply Last reply Reply Quote 0
            • karsten13K Offline
              karsten13
              last edited by

              you could use a proxy https://cors-anywhere.herokuapp.com/https://dd.weather.gc.ca/citypage_weather/xml/ON/s0000326_e.xmll, there is already such a line in the PullRequest merged today.

              crazylegsC 1 Reply Last reply Reply Quote 1
              • crazylegsC Offline
                crazylegs @karsten13
                last edited by

                @karsten13 Thanks for highlighting this! I did a quick-and-dirty test in my code using this proxy and I’m now able to pull back the data from the EnvCanada provider! I will likely need to override the default fetchData function since it expects to JSON.parse the Provider data. This is not quite what I need since EnvCanada just provides an XML document to parse (JSON.parse fails…). But now I can at least start playing around some more.

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                • First post
                  Last post
                Enjoying MagicMirror? Please consider a donation!
                MagicMirror created by Michael Teeuw.
                Forum managed by Sam, technical setup by Karsten.
                This forum is using NodeBB as its core | Contributors
                Contact | Privacy Policy