netbymatt / ws4kp

WeatherStar 4000+
https://weatherstar.netbymatt.com
MIT License
236 stars 39 forks source link

install not working #14

Closed silver-dragon closed 1 year ago

silver-dragon commented 1 year ago

Server Environment: Fedora Server 36 VM on Proxmox Firewall disabled, SELINUX Disabled Node 16.14.0 NPM 8.19.2

Client Environment: Firefox 105.0.1 (https://weatherstar.netbymatt.com/ runs fine in this same browser)

Steps:

  1. Install and setup fresh copy of fedora server with all updates.
  2. Install git and node.js
  3. pull repo, enter repo dir
  4. install dependency node install package.json
  5. run index.js node index.js
  6. Open browser to http://weather-star:8080/
  7. Enter location and click go

Problem: Entering in any location and clicking go does nothing. The display never refreshes and just remains at:

WeatherStar 4000+ Enter your location above to continue

I am not sure if I have installed correctly, maybe there is some dependency I am missing or maybe a config file setup I don't know about. Or maybe its a bug. Not sure So this could be either a bug report or a request for a more detailed install guide.

markcaudill commented 1 year ago

This is due to a CORS issue:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/find?text=REDACTED&magicKey=REDACTED&f=json. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Status code: 400.

I'm not up to speed on these problems so I don't have a resolution per se. But a very crude workaround is if you go to the URL you see in the dev console, you can paste that JSON response into https://github.com/netbymatt/ws4kp/blob/52efea0b6755573681a4d10ad91dc31d89c474f7/server/scripts/index.js#L177-L183

index 5a42116..56f3605 100644
--- a/server/scripts/index.js
+++ b/server/scripts/index.js
@@ -174,13 +174,16 @@ const index = (() => {
                if (overrides[suggestion.value]) {
                        doRedirectToGeometry(overrides[suggestion.value]);
                } else {
-                       const data = await utils.fetch.json('https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/find', {
-                               data: {
-                                       text: suggestion.value,
-                                       magicKey: suggestion.data,
-                                       f: 'json',
-                               },
-                       });
+                       const data = {
+                               spatialReference: { wkid: REDACTED, latestWkid: REDACTED },
+                               locations: [{
+                                       name: 'REDACTED',
+                                       extent: {
+                                               xmin: REDACTED, ymin: REDACTED, xmax: REDACTED, ymax: REDACTED,
+                                       },
+                                       feature: { geometry: { x: REDACTED, y: REDACTED }, attributes: { Score: 100, Addr_Type: 'Postal' } },
+                               }],
+                       };

                        const loc = data.locations[0];
                        if (loc) {
gtxaspec commented 1 year ago

I think this would be fixed if SSL was enabled. Is it possible to enable ssl with node?

netbymatt commented 1 year ago

I think there are two separate issues to deal with here.

  1. geocode.arcgis.com appears to have dropped http-only support. I'm using a fetch routine that matches the protocol for the fetch to the pages protocol. This means that https is reduced to http for this call and then fails with a http 400 error. I can work on this issue.
  2. You may be causing a CORS error by naming your server weather-star. I would have to dig into this further but I thought localhost allows for some special considerations around CORS and https for the purposes of local debugging. Can you try running it as localhost and see if the cors error becomes a http 400 error?

@gtxaspec Yes, you can use SSL with node. But it becomes messy because you have to create a self-signed certificate and then install that certificate in your browser. You can find npm packages and plenty of tutorials on how to accomplish this. But it's my goal to have this run locally without any special workarounds.