How to migrate Graphhopper server from http://localhost:8989 to a publicly queryable web-server

This is probably a basic question. I’ve reviewed the forums and Github Deploy Documentation, but am still having trouble. I have successful run the localhost:8989 server, and my localhost website is able to query directions. I have also successfully started up a vultr.com web-server of the same graphhopper files, I haven’t been able to query the web-server.

I’m sure there is some simple regarding, IP address, Port numbers, or Javascript code that I am missing… When going from localhost:8989 to a web-server is something suppose to change in the config.yml file? Or the main.js file from the graphhopper-javascript-api documentation? Can anyone spot my error? Or just walk me through the migration process with more detail than the Github Deploy Documentation?

Thank you, Hope everyone is safe and well
Dylan

My Vultr.com Web-Server:
CPU: 1 vCore
RAM: 1024 MB
Storage: 25 GB SSD
Bandwidth: [1.51 GB of 1000 GB]
OS: Ubuntu 20.04 x64

When connected to my server I run:

./graphhopper.sh -a web -i ./data/tucson.osm.pbf -o ./data/tucson-gh -d --port 8989

Which results in…

## using java 11.0.7 (64bit) from
## using existing osm file ./data/tucson.osm.pbf
## existing jar found web/target/graphhopper-web-1.0-SNAPSHOT.jar
## now web. JAVA_OPTS=-Xmx1000m -Xms1000m
root@Pathways:~/routing_v2/graphhopper# 2020-07-14 23:03:44.343 [main] INFO  i.d.server.DefaultServerFactory - Registering jersey handler with root path prefix: /
2020-07-14 23:03:44.361 [main] INFO  i.d.server.DefaultServerFactory - Registering admin handler with root path prefix: /
2020-07-14 23:03:50.422 [main] INFO  i.d.b.assets.ConfiguredAssetsBundle - Registering ConfiguredAssetBundle with name: assets for path /webjars/*
2020-07-14 23:03:50.427 [main] INFO  i.d.b.assets.ConfiguredAssetsBundle - Registering ConfiguredAssetBundle with name: assets for path /maps/*
2020-07-14 23:03:50.429 [main] WARN  i.d.jetty.setup.ServletEnvironment - Overriding the existing servlet registered with the name: assets
2020-07-14 23:03:50.524 [main] INFO  io.dropwizard.server.ServerFactory - Starting GraphHopperApplication
                        _     _
   __ _ _ __ __ _ _ __ | |__ | |__   ___  _ __  _ __   ___ _ __
  / _` | '__/ _` | '_ \| '_ \| '_ \ / _ \| '_ \| '_ \ / _ \ '__|
 | (_| | | | (_| | |_) | | | | | | | (_) | |_) | |_) |  __/ |
  \__, |_|  \__,_| .__/|_| |_|_| |_|\___/| .__/| .__/ \___|_|
  |___/          |_|                     |_|   |_|
2020-07-14 23:03:50.796 [main] INFO  o.e.jetty.setuid.SetUIDListener - Opened application@a4b5ce3{HTTP/1.1, (http/1.1)}{localhost:8989}
2020-07-14 23:03:50.797 [main] INFO  o.e.jetty.setuid.SetUIDListener - Opened admin@f5b6e78{HTTP/1.1, (http/1.1)}{localhost:8990}
2020-07-14 23:03:50.800 [main] INFO  org.eclipse.jetty.server.Server - jetty-9.4.28.v20200408; built: 2020-04-08T17:49:39.557Z; git: ab228fde9e55e9164c738d7fa121f8ac5acd51c9; jvm 11.0.7+10-post-Ubuntu-3ubuntu1
2020-07-14 23:03:50.994 [main] INFO  c.g.reader.osm.GraphHopperOSM - version 1.0|2020-07-12T20:01:09Z (5,15,4,3,5,6)
2020-07-14 23:03:50.999 [main] INFO  c.g.reader.osm.GraphHopperOSM - graph CH|bike|RAM_STORE|2D|no_turn_cost|5,15,4,3,5, details:edges:42 884(2MB), nodes:28 753(1MB), name:(1MB), geo:53 807(1MB), bounds:-111.01178327974192,-110.85086433256114,32.17434787394884,32.29932950361064, CHGraph|tucsonpathways|NODE_BASED, shortcuts:35 927, nodesCH:(1MB)
2020-07-14 23:03:51.001 [main] INFO  c.g.http.GraphHopperManaged - loaded graph at:./data/tucson-gh, data_reader_file:./data/tucson.osm.pbf, encoded values:roundabout|version=283388307|bits=1|index=0|shift=0|store_both_directions=false,road_class|version=2007543510|bits=5|index=0|shift=1|store_both_directions=false,road_class_link|version=146075245|bits=1|index=0|shift=6|store_both_directions=false,road_environment|version=-446726394|bits=3|index=0|shift=7|store_both_directions=false,max_speed|version=-1300485567|bits=5|index=0|shift=10|store_both_directions=true,road_access|version=-313723172|bits=4|index=0|shift=20|store_both_directions=false,bike_network|version=-235982830|bits=3|index=0|shift=24|store_both_directions=false,get_off_bike|version=2140540190|bits=1|index=0|shift=27|store_both_directions=false, edges:42 884(2MB), nodes:28 753(1MB), name:(1MB), geo:53 807(1MB), bounds:-111.01178327974192,-110.85086433256114,32.17434787394884,32.29932950361064, CHGraph|tucsonpathways|NODE_BASED, shortcuts:35 927, nodesCH:(1MB)
2020-07-14 23:03:52.358 [main] INFO  i.d.jersey.DropwizardResourceConfig - The following paths were found for the configured resources:

    GET     / (com.graphhopper.http.resources.RootResource)
    GET     /i18n (com.graphhopper.resources.I18NResource)
    GET     /i18n/{locale} (com.graphhopper.resources.I18NResource)
    GET     /info (com.graphhopper.resources.InfoResource)
    GET     /isochrone (com.graphhopper.resources.IsochroneResource)
    GET     /mvt/{z}/{x}/{y}.mvt (com.graphhopper.resources.MVTResource)
    GET     /nearest (com.graphhopper.resources.NearestResource)
    GET     /route (com.graphhopper.resources.RouteResource)
    POST    /route (com.graphhopper.resources.RouteResource)
    POST    /route-custom (com.graphhopper.resources.CustomWeightingRouteResource)
    GET     /spt (com.graphhopper.resources.SPTResource)

2020-07-14 23:03:52.362 [main] INFO  o.e.j.server.handler.ContextHandler - Started i.d.j.MutableServletContextHandler@33ec2c0c{/,null,AVAILABLE}
2020-07-14 23:03:52.376 [main] INFO  io.dropwizard.setup.AdminEnvironment - tasks =

    POST    /tasks/log-level (io.dropwizard.servlets.tasks.LogConfigurationTask)
    POST    /tasks/gc (io.dropwizard.servlets.tasks.GarbageCollectionTask)

2020-07-14 23:03:52.400 [main] INFO  o.e.j.server.handler.ContextHandler - Started i.d.j.MutableServletContextHandler@50598a1a{/,null,AVAILABLE}
2020-07-14 23:03:52.432 [main] INFO  o.e.jetty.server.AbstractConnector - Started application@a4b5ce3{HTTP/1.1, (http/1.1)}{localhost:8989}
2020-07-14 23:03:52.442 [main] INFO  o.e.jetty.server.AbstractConnector - Started admin@f5b6e78{HTTP/1.1, (http/1.1)}{localhost:8990}
2020-07-14 23:03:52.442 [main] INFO  org.eclipse.jetty.server.Server - Started @12674ms

With these netstat connections:

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      521/systemd-resolve
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      616/sshd: /usr/sbin
tcp6       0      0 :::22                   :::*                    LISTEN      616/sshd: /usr/sbin
tcp6       0      0 127.0.0.1:8989          :::*                    LISTEN      2588/java
tcp6       0      0 127.0.0.1:8990          :::*                    LISTEN      2588/java

My config.yml file used to build my graphhopper-graphs and graphhopper-server:

graphhopper:

  # OpenStreetMap input file PBF or XML, can be changed via command line -Ddw.graphhopper.datareader.file=some.pbf
  datareader.file: ""
  # Local folder used by graphhopper to store its data
  graph.location: graph-cache

  ##### Vehicles #####


  # More options: foot,hike,bike,bike2,mtb,racingbike,motorcycle,car4wd,wheelchair (comma separated)
  # bike2 takes elevation data into account (like up-hill is slower than down-hill) and requires enabling graph.elevation.provider below.
  graph.flag_encoders: bike
  # To prevent long running routing queries you should usually enable either speed or hybrid mode for all the given
  # profiles (see below). Otherwise you should at least limit the number of `routing.max_visited_nodes`.
  profiles:
  - name: tucsonpathways
    vehicle: bike
    weighting: custom
    custom_model_file: v1.yml
  # Speed mode:
  # Its possible to speed up routing by doing a special graph preparation (Contraction Hierarchies, CH). This requires
  # more RAM/disk space for holding the prepared graph but also means less memory usage per request. Using the following
  # list you can define for which of the above routing profiles such preparation shall be performed. Note that to support
  # profiles with `turn_costs: true` a more elaborate preparation is required (longer preparation time and more memory
  # usage) and the routing will also be slower than with `turn_costs: false`.
  profiles_ch:
    - profile: tucsonpathways
  #   - profile: car_with_turn_costs
  # Hybrid mode:
  # Similar to speed mode, the hybrid mode (Landmarks, LM) also speeds up routing by doing calculating auxiliary data
  # in advance. Its not as fast as speed mode, but more flexible.
  #
  # Advanced usage: It is possible to use the same preparation for multiple profiles which saves memory and preparation
  # time. To do this use e.g. `preparation_profile: my_other_profile` where `my_other_profile` is the name of another
  # profile for which an LM profile exists. Important: This only will give correct routing results if the weights
  # calculated for the profile are equal or larger (for every edge) than those calculated for the profile that was used
  # for the preparation (`my_other_profile`)
  profiles_lm: []
  # In many cases the road network consists of independent components without any routes going in between. In
  # the most simple case you can imagine an island without a bridge or ferry connection. The following parameter
  # allows setting a minimum size (number of nodes) for such detached components. This can be used to reduce the number
  # of cases where a connection between locations might not be found.
  prepare.min_network_size: 200
  # You can limit the max distance between two consecutive waypoints of flexible routing requests to be less or equal
  # the given distance in meter. Default is set to 1000km.
  routing.non_ch.max_waypoint_distance: 1000000
  # configure the memory access, use RAM_STORE for well equipped servers (default and recommended)
  graph.dataaccess: RAM_STORE
# Dropwizard server configuration
server:
  application_connectors:
  - type: http
    port: 8989
    # for security reasons bind to localhost
    bind_host: localhost #does this need to change to my web-server's IP Address?
  request_log:
      appenders: []
  admin_connectors:
  - type: http
    port: 8990
    bind_host: localhost #does this need to change to my web-server's IP Address?
# See https://www.dropwizard.io/1.3.8/docs/manual/configuration.html#logging
logging:
  appenders:
  - type: file
    time_zone: UTC
    current_log_filename: logs/graphhopper.log
    log_format: "%d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n"
    archive: true
    archived_log_filename_pattern: ./logs/graphhopper-%d.log.gz
    archived_file_count: 30
    never_block: true
  - type: console
    time_zone: UTC
    log_format: "%d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n"

My website’s graphhopper-javascript api is pretty much the default code from the documentation:

... additional code ...

let parameters = {
  host: "http://localhost:8989", //Should this be changed to my web-servers IP Address? 
  vehicle: "bike",
  elevation: false,
  details: ["road_class", "distance"]
}

let ghRouting = new GraphHopper.Routing(parameters);
      ghRouting.addPoint(new GHInput(startMarker.getLngLat().lat, startMarker.getLngLat().lng));
      ghRouting.addPoint(new GHInput(endMarker.getLngLat().lat, endMarker.getLngLat().lng));
      ghRouting.doRequest()
        .then(function(json) {
          // Add your own result handling here
          AllPOIs[endMarker.id].geojson = json;
          myRoute.showOnMap(endMarker);
          CO2.Display();
        })
        .catch(function(err) {
          console.error(err.message);
        });
    };

... additional code ...

Probably you only have to remove this line

Probably you only have to remove this line

That was half of the solution but yes - solved! Additionally, I needed to change my website’s javascript code from:

...
let parameters = {
  host: "http://localhost:8989", //Should this be changed to my web-servers IP Address? 
  vehicle: "bike",
  elevation: false,
  details: ["road_class", "distance"]
}
...

to…

...
let parameters = {
  host: "<PUBLIC.IP.ADDRESS.OF.SERVER>:8989", //8989 is the default port from the config file, but whatever port you are using.
  vehicle: "bike",
  elevation: false,
  details: ["road_class", "distance"]
}
...

Thank you again @karussell, I hope you are well!
Dylan

1 Like
Powered by Discourse