Skip to content

Commit

Permalink
Prepared for HTTPS and working together with Let's Encrypt certbot
Browse files Browse the repository at this point in the history
  • Loading branch information
ddekany committed May 15, 2018
1 parent 53c2674 commit 62980b6
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -61,7 +61,7 @@ dependencies {
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
Expand Down
1 change: 1 addition & 0 deletions dependencies.gradle
Expand Up @@ -27,6 +27,7 @@ ext.libraries = [
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:
Expand Down
Expand Up @@ -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> {
Expand Down Expand Up @@ -61,11 +64,19 @@ public Map<String, Map<String, String>> getViewConfiguration(FreeMarkerOnlineTes
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")
));
}
}
Expand Up @@ -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() {
Expand All @@ -39,4 +42,15 @@ public void setViewRendererConfiguration(Map<String, Map<String, String>> viewRe
this.viewRendererConfiguration = viewRendererConfiguration;
}

@JsonProperty("assets")
@Override
public AssetsConfiguration getAssetsConfiguration() {
return assetsConfiguration;
}

@JsonProperty("assets")
public void setAssetsConfiguration(AssetsConfiguration assetsConfiguration) {
this.assetsConfiguration = assetsConfiguration;
}

}
23 changes: 21 additions & 2 deletions src/main/resources/freemarker-online.yml
Expand Up @@ -22,7 +22,7 @@ logging:
- type: console
threshold: ALL
target: stdout
# # For production:
# # FOR PRODUCTION:
# - type: file
# currentLogFilename: /opt/fmonlinetester/var/log/main.log
# threshold: ALL
Expand All @@ -34,10 +34,29 @@ logging:
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
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

0 comments on commit 62980b6

Please sign in to comment.