Prepared for HTTPS and working together with Let's Encrypt certbot
diff --git a/build.gradle b/build.gradle
index df3fcae..59d7907 100644
--- a/build.gradle
+++ b/build.gradle
@@ -61,7 +61,7 @@
compile libraries.dropwizard
compile libraries.dropwizard_views
compile libraries.dropwizard_views_freemarker
- compile libraries.dropwizard_assets
+ compile libraries.dropwizard_configurable_assets
compile libraries.dropwizard_bundles_redirect
compile libraries.freemarker
compile libraries.commonLangs
diff --git a/dependencies.gradle b/dependencies.gradle
index d957ff8..635c92c 100644
--- a/dependencies.gradle
+++ b/dependencies.gradle
@@ -27,6 +27,7 @@
dropwizard_views: "io.dropwizard:dropwizard-views:$dropwizard_version",
dropwizard_views_freemarker: "io.dropwizard:dropwizard-views-freemarker:$dropwizard_version",
dropwizard_assets: "io.dropwizard:dropwizard-assets:$dropwizard_version",
+ dropwizard_configurable_assets: "io.dropwizard-bundles:dropwizard-configurable-assets-bundle:1.0.5",
dropwizard_bundles_redirect: "io.dropwizard-bundles:dropwizard-redirect-bundle:1.2.2",
// App. specific:
diff --git a/src/main/java/org/apache/freemarker/onlinetester/dropwizard/FreeMarkerOnlineTester.java b/src/main/java/org/apache/freemarker/onlinetester/dropwizard/FreeMarkerOnlineTester.java
index 40dab6e..563720a 100644
--- a/src/main/java/org/apache/freemarker/onlinetester/dropwizard/FreeMarkerOnlineTester.java
+++ b/src/main/java/org/apache/freemarker/onlinetester/dropwizard/FreeMarkerOnlineTester.java
@@ -26,12 +26,15 @@
import org.apache.freemarker.onlinetester.resources.WebPageResource;
import org.apache.freemarker.onlinetester.services.FreeMarkerService;
+import com.google.common.collect.ImmutableMap;
+
import io.dropwizard.Application;
-import io.dropwizard.assets.AssetsBundle;
+import io.dropwizard.bundles.assets.ConfiguredAssetsBundle;
import io.dropwizard.bundles.redirect.RedirectBundle;
import io.dropwizard.bundles.redirect.UriRedirect;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
+import io.dropwizard.sslreload.SslReloadBundle;
import io.dropwizard.views.ViewBundle;
public class FreeMarkerOnlineTester extends Application<FreeMarkerOnlineTesterConfiguration> {
@@ -61,11 +64,19 @@
return config.getViewRendererConfiguration();
}
});
- bootstrap.addBundle(new AssetsBundle());
+ bootstrap.addBundle(new SslReloadBundle());
+ bootstrap.addBundle(new ConfiguredAssetsBundle(
+ ImmutableMap.of(
+ "/assets/", "/assets/", // css, js, images...
+ "/letsencrypt-verify", "/letsencrypt-verify" // Map to a file outside the jar in the yml!
+ )));
bootstrap.addBundle(new RedirectBundle(
new UriRedirect(
"http://freemarker-online.kenshoo.com([:/].*)$",
- "http://try.freemarker.org$1")
+ "http://try.freemarker.org$1"),
+ new UriRedirect(
+ "http://try.freemarker.apache.org([:/].*)$",
+ "https://try.freemarker.apache.org$1")
));
}
}
diff --git a/src/main/java/org/apache/freemarker/onlinetester/dropwizard/FreeMarkerOnlineTesterConfiguration.java b/src/main/java/org/apache/freemarker/onlinetester/dropwizard/FreeMarkerOnlineTesterConfiguration.java
index b29622c..f0b9122 100644
--- a/src/main/java/org/apache/freemarker/onlinetester/dropwizard/FreeMarkerOnlineTesterConfiguration.java
+++ b/src/main/java/org/apache/freemarker/onlinetester/dropwizard/FreeMarkerOnlineTesterConfiguration.java
@@ -24,10 +24,13 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import io.dropwizard.Configuration;
+import io.dropwizard.bundles.assets.AssetsBundleConfiguration;
+import io.dropwizard.bundles.assets.AssetsConfiguration;
-public class FreeMarkerOnlineTesterConfiguration extends Configuration {
+public class FreeMarkerOnlineTesterConfiguration extends Configuration implements AssetsBundleConfiguration {
private Map<String, Map<String, String>> viewRendererConfiguration;
+ private AssetsConfiguration assetsConfiguration;
@JsonProperty("viewRendererConfiguration")
public Map<String, Map<String, String>> getViewRendererConfiguration() {
@@ -39,4 +42,15 @@
this.viewRendererConfiguration = viewRendererConfiguration;
}
+ @JsonProperty("assets")
+ @Override
+ public AssetsConfiguration getAssetsConfiguration() {
+ return assetsConfiguration;
+ }
+
+ @JsonProperty("assets")
+ public void setAssetsConfiguration(AssetsConfiguration assetsConfiguration) {
+ this.assetsConfiguration = assetsConfiguration;
+ }
+
}
diff --git a/src/main/resources/freemarker-online.yml b/src/main/resources/freemarker-online.yml
index c1268b2..1ffb937 100644
--- a/src/main/resources/freemarker-online.yml
+++ b/src/main/resources/freemarker-online.yml
@@ -22,7 +22,7 @@
- type: console
threshold: ALL
target: stdout
-# # For production:
+# # FOR PRODUCTION:
# - type: file
# currentLogFilename: /opt/fmonlinetester/var/log/main.log
# threshold: ALL
@@ -34,10 +34,29 @@
server:
requestLog:
appenders: []
+ applicationConnectors:
+ - type: http
+ port: 8080
+# # FOR PRODUCTION:
+# - type: https
+# port: 8443
+# keyStorePath: /etc/letsencrypt/live/example.p12
+# keyStoreType: PKCS12
+# keyStorePassword: secret
+# validateCerts: false
+ adminConnectors:
+ # HTTP POST to /tasks/reload-ssl to reload SSL certificates without stopping.
+ - type: http
+ port: 8081
viewRendererConfiguration:
freemarker: # was `.ftl:` before Dropwizard 1.3.0
incompatibleImprovements: 2.3.28
locale: en_US
timeZone: UTC
outputEncoding: UTF-8
- templateExceptionHandler: rethrow
\ No newline at end of file
+ templateExceptionHandler: rethrow
+assets:
+ overrides:
+ # Let's Encrypt certbot writes its domain ownership vertification file here. It will visit
+ # it from outside when we ask for a new certificate:
+ /letsencrypt-verify: /opt/fmonlinetester/var/letsencrypt-verify
\ No newline at end of file