Skip to content

Commit 17ec0b0

Browse files
authored
Remove configurable-assets-bundle (graphhopper#2238)
1 parent 522bc60 commit 17ec0b0

File tree

11 files changed

+41
-69
lines changed

11 files changed

+41
-69
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ android/libs/graphhopper-*-android.jar
1616
.idea/
1717
*iml
1818
/web/src/main/resources/assets/js/config/options_prod.js
19+
/web/src/main/resources/assets/js/main.js
1920
/web/dependency-reduced-pom.xml
2021
/web/node
2122
*.pbf

config-example.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,6 @@ graphhopper:
172172
# Having less rules, might result in a smaller graph. The line below contains the world-wide bounding box, uncomment and adapt to your need.
173173
# spatial_rules.max_bbox: -180,180,-90,90
174174

175-
176-
# Uncomment the following to point /maps to the source directory in the filesystem instead of
177-
# the Java resource path. Helpful for development of the web client.
178-
# Assumes that the web module is the working directory.
179-
#
180-
# assets:
181-
# overrides:
182-
# /maps: web/target/classes/assets/
183-
184175
# Dropwizard server configuration
185176
server:
186177
application_connectors:

docs/core/quickstart-from-source.md

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -94,37 +94,38 @@ as those versions are not in maven central:
9494
</repositories>
9595
```
9696

97-
### JavaScript
98-
99-
When developing the UI for GraphHopper you need to enable serving files
100-
directly from local disc via your config.yml:
101-
102-
```yml
103-
assets:
104-
overrides:
105-
/maps: web/src/main/resources/assets/
106-
```
97+
### Web UI (JavaScript)
10798

10899
To setup the JavaScript development environment install the [node package
109-
manager](https://github.com/nvm-sh/nvm):
100+
manager](https://github.com/nvm-sh/nvm#install--update-script). For windows use [nvm-windows](https://github.com/coreybutler/nvm-windows).
101+
102+
To develop the web UI you need to rebuild the bundled main.js on every change. npm does this for you automatically:
110103

111104
```bash
112-
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash && \. $HOME/.nvm/nvm.sh && nvm install
113-
# create main.js via npm
114-
cd web && npm install && npm run bundleProduction && cd ..
105+
cd web
106+
npm run watch
115107
```
116108

117-
For windows use [nvm-windows](https://github.com/coreybutler/nvm-windows).
109+
To see your changes in the browser without restarting the server you can either run the GH server in debug mode from
110+
IntelliJ (use `Run->Debugging Actions->Reload Changed Classes` and refresh your browser window).
111+
112+
Or you start a separate server. For this you need to change the routing.host property in src/main/resources/assets/js/config/options.js:
113+
```js
114+
...
115+
routing: {host: 'http://localhost:8989', api_key: ''},
116+
...
117+
```
118118

119-
There are more npm commands to e.g. change the main.js on the fly or create an uglified main.js for
120-
production:
119+
And then in a second shell do:
121120

122-
```bash
123-
cd web
121+
```
122+
npm install -g live-server
123+
live-server --open=src/main/resources/assets/
124+
```
124125

125-
# For development just use watchify and all changes will be available on refresh:
126-
npm run watch
126+
Other npm commands e.g. to produce a bundled main.js for production:
127127

128+
```bash
128129
# bundle creates the main file
129130
npm run bundle
130131

pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,10 @@
9090
<dependency>
9191
<groupId>io.dropwizard</groupId>
9292
<artifactId>dropwizard-dependencies</artifactId>
93-
<!-- make sure the dropwizard version is compatible to the below dropwizard-configurable-assets-bundle version -->
9493
<version>2.0.16</version>
9594
<type>pom</type>
9695
<scope>import</scope>
9796
</dependency>
98-
<dependency>
99-
<groupId>io.dropwizard-bundles</groupId>
100-
<artifactId>dropwizard-configurable-assets-bundle</artifactId>
101-
<version>1.3.5</version>
102-
</dependency>
10397
<dependency>
10498
<groupId>com.graphhopper.external</groupId>
10599
<artifactId>jackson-datatype-jts</artifactId>

web/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
"license": "Apache-2.0",
77
"main": "main.js",
88
"scripts": {
9-
"watch": "watchify src/main/resources/assets/js/main-template.js -o target/classes/assets/js/main.js --debug --verbose",
10-
"bundle": "browserify src/main/resources/assets/js/main-template.js -o target/classes/assets/js/main.js",
11-
"bundleDebug": "browserify src/main/resources/assets/js/main-template.js --debug -o target/classes/assets/js/main.js",
12-
"bundleProduction": "browserify -g uglifyify src/main/resources/assets/js/main-template.js -o target/classes/assets/js/main.js",
9+
"watch": "watchify src/main/resources/assets/js/main-template.js -o src/main/resources/assets/js/main.js --debug --verbose",
10+
"bundle": "browserify src/main/resources/assets/js/main-template.js -o src/main/resources/assets/js/main.js",
11+
"bundleDebug": "browserify src/main/resources/assets/js/main-template.js --debug -o src/main/resources/assets/js/main.js",
12+
"bundleProduction": "browserify -g uglifyify src/main/resources/assets/js/main-template.js -o src/main/resources/assets/js/main.js",
1313
"test": "JASMINE_CONFIG_PATH=src/test/resources/assets/spec/jasmine.json jasmine",
1414
"lint": "jshint src/main/resources/assets/js/"
1515
},

web/pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
<groupId>io.dropwizard</groupId>
2424
<artifactId>dropwizard-core</artifactId>
2525
</dependency>
26+
<dependency>
27+
<groupId>io.dropwizard</groupId>
28+
<artifactId>dropwizard-assets</artifactId>
29+
</dependency>
2630
<dependency>
2731
<groupId>com.graphhopper</groupId>
2832
<artifactId>graphhopper-web-bundle</artifactId>
@@ -33,10 +37,6 @@
3337
<artifactId>graphhopper-nav</artifactId>
3438
<version>${project.parent.version}</version>
3539
</dependency>
36-
<dependency>
37-
<groupId>io.dropwizard-bundles</groupId>
38-
<artifactId>dropwizard-configurable-assets-bundle</artifactId>
39-
</dependency>
4040

4141
<!-- Pt and/or map-matching and/or isochrone web client dependencies-->
4242
<dependency>

web/src/main/java/com/graphhopper/http/CORSFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
3030
HttpServletResponse rsp = (HttpServletResponse) response;
3131
rsp.setHeader("Access-Control-Allow-Methods", "GET, POST, HEAD, OPTIONS");
3232
rsp.setHeader("Access-Control-Allow-Headers", "Origin,Accept,X-Requested-With,"
33-
+ "Content-Type,Access-Control-Request-Method,Access-Control-Request-Headers,Range");
33+
+ "Content-Type,Access-Control-Request-Method,Access-Control-Request-Headers,Range,gh-client");
3434
rsp.setHeader("Access-Control-Allow-Origin", "*");
3535

3636
chain.doFilter(request, response);

web/src/main/java/com/graphhopper/http/GraphHopperApplication.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@
2222
import com.graphhopper.http.resources.RootResource;
2323
import com.graphhopper.navigation.NavigateResource;
2424
import io.dropwizard.Application;
25-
import io.dropwizard.bundles.assets.ConfiguredAssetsBundle;
25+
import io.dropwizard.assets.AssetsBundle;
2626
import io.dropwizard.setup.Bootstrap;
2727
import io.dropwizard.setup.Environment;
2828

2929
import javax.servlet.DispatcherType;
3030
import java.util.EnumSet;
31-
import java.util.HashMap;
32-
import java.util.Map;
3331

3432
public final class GraphHopperApplication extends Application<GraphHopperServerConfiguration> {
3533

@@ -43,11 +41,9 @@ public void initialize(Bootstrap<GraphHopperServerConfiguration> bootstrap) {
4341
bootstrap.addBundle(new RealtimeBundle());
4442
bootstrap.addCommand(new ImportCommand());
4543
bootstrap.addCommand(new MatchCommand());
46-
47-
Map<String, String> resourceToURIMappings = new HashMap<>();
48-
resourceToURIMappings.put("/assets/", "/maps/");
49-
resourceToURIMappings.put("/META-INF/resources/webjars", "/webjars"); // https://www.webjars.org/documentation#dropwizard
50-
bootstrap.addBundle(new ConfiguredAssetsBundle(resourceToURIMappings, "index.html"));
44+
bootstrap.addBundle(new AssetsBundle("/assets/", "/maps/", "index.html"));
45+
// see this link even though its outdated?! // https://www.webjars.org/documentation#dropwizard
46+
bootstrap.addBundle(new AssetsBundle("/META-INF/resources/webjars", "/webjars/", null, "webjars"));
5147
}
5248

5349
@Override

web/src/main/java/com/graphhopper/http/GraphHopperServerConfiguration.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,15 @@
2020
import com.fasterxml.jackson.annotation.JsonProperty;
2121
import com.graphhopper.GraphHopperConfig;
2222
import io.dropwizard.Configuration;
23-
import io.dropwizard.bundles.assets.AssetsBundleConfiguration;
24-
import io.dropwizard.bundles.assets.AssetsConfiguration;
2523

26-
import javax.validation.Valid;
2724
import javax.validation.constraints.NotNull;
2825

29-
public class GraphHopperServerConfiguration extends Configuration implements GraphHopperBundleConfiguration, RealtimeBundleConfiguration, AssetsBundleConfiguration {
26+
public class GraphHopperServerConfiguration extends Configuration implements GraphHopperBundleConfiguration, RealtimeBundleConfiguration {
3027

3128
@NotNull
3229
@JsonProperty
3330
private final GraphHopperConfig graphhopper = new GraphHopperConfig();
3431

35-
@Valid
36-
@JsonProperty
37-
private final AssetsConfiguration assets = AssetsConfiguration.builder().build();
38-
3932
@JsonProperty
4033
private final RealtimeConfiguration gtfsRealtime = new RealtimeConfiguration();
4134

@@ -47,11 +40,6 @@ public GraphHopperConfig getGraphHopperConfiguration() {
4740
return graphhopper;
4841
}
4942

50-
@Override
51-
public AssetsConfiguration getAssetsConfiguration() {
52-
return assets;
53-
}
54-
5543
@Override
5644
public RealtimeConfiguration gtfsrealtime() {
5745
return gtfsRealtime;

web/src/main/resources/assets/js/config/options.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
// Misuse of API keys that you don't own is prohibited and you'll be blocked.
66
////////////////////////////////////////////////////////////////////////////////////////////////////////
77

8-
// Easily replace this options.js with an additional file that you prodive as options_prod.js activate via:
8+
// Easily replace this options.js with an additional file that you provide as options_prod.js activate via:
99
// BROWSERIFYSWAP_ENV='production' npm run watch
1010
// see also package.json and https://github.com/thlorenz/browserify-swap
1111
exports.options = {
1212
with_tiles: true,
1313
environment: "development",
14+
// for local development use this (assuming your GH server is running on the standard port)
15+
// routing: {host: 'http://localhost:8989', api_key: ''},
1416
routing: {host: '', api_key: ''},
1517
geocoding: {host: '', api_key: ''},
1618
thunderforest: {api_key: ''},

web/src/main/resources/assets/js/graphhopper/GHRequest.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,7 @@ GHRequest.prototype.doRequest = function (url, callback) {
256256
timeout: 30000,
257257
url: url,
258258
beforeSend: function(request) {
259-
request.setRequestHeader("gh-client", "web-ui")
260-
request.setRequestHeader("gh-client-version", "1.0")
259+
request.setRequestHeader("gh-client", "web-ui 3.0")
261260
},
262261
success: function (json) {
263262
if (json.paths) {

0 commit comments

Comments
 (0)