Add ability to set base path in dev mode

Change-Id: I1da95745d1bc8eaa7d5b204a942bcee0b6a027a8
diff --git a/Documentation/config.md b/Documentation/config.md
index 6c5eac3..869129a 100644
--- a/Documentation/config.md
+++ b/Documentation/config.md
@@ -30,6 +30,8 @@
   mode for that file. The link will only appear when you are browsing the file
   at a branch, so the commitish must start with `refs/heads/`.
 
+`basePath` the base path for the gitiles urls. (only applicable for dev mode.)
+
 > If you are using the Gerrit Gitiles plugin, this is set based on Gerrit's configuration.
 > Default: `null`, do not link `Change-Id` or show edit links.
 
@@ -38,6 +40,7 @@
   canonicalHostName = gitiles.example.org
   gerritUrl = https://gerrit.example.org/r/
   baseGitUrl = git://git.example.org/
+  basePath = /additional/basepath/for/gitiles/
 ```
 
 ### Repositories export
diff --git a/java/com/google/gitiles/dev/DevServer.java b/java/com/google/gitiles/dev/DevServer.java
index 675511b..f278239 100644
--- a/java/com/google/gitiles/dev/DevServer.java
+++ b/java/com/google/gitiles/dev/DevServer.java
@@ -17,6 +17,7 @@
 import static com.google.common.base.MoreObjects.firstNonNull;
 import static com.google.gitiles.GitilesServlet.STATIC_PREFIX;
 
+import com.google.common.base.MoreObjects;
 import com.google.common.base.Strings;
 import com.google.common.html.types.UncheckedConversions;
 import com.google.gitiles.BranchRedirect;
@@ -125,7 +126,7 @@
     return handlers;
   }
 
-  private Handler appHandler() {
+  private Handler appHandler() throws UnknownHostException {
     DebugRenderer renderer =
         new DebugRenderer(
             STATIC_PREFIX,
@@ -144,7 +145,7 @@
     }
 
     ServletContextHandler handler = new ServletContextHandler();
-    handler.setContextPath("");
+    handler.setContextPath(MoreObjects.firstNonNull(cfg.getString("gitiles", null, "basePath"), ""));
     handler.addServlet(new ServletHolder(servlet), "/*");
     return handler;
   }