diff options
author | Anton Tananaev <anton@traccar.org> | 2022-06-04 20:15:03 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2022-06-04 20:15:03 -0700 |
commit | 3b5c04b4ddf71223371815575fa1b652fea1d5da (patch) | |
tree | 75e2942d12c8891e44d2a175f099c19a65156507 /src/main/java/org/traccar/web/WebServer.java | |
parent | b6ec84dbb4e1e2e212b0d6195920407a43919ab5 (diff) | |
download | trackermap-server-3b5c04b4ddf71223371815575fa1b652fea1d5da.tar.gz trackermap-server-3b5c04b4ddf71223371815575fa1b652fea1d5da.tar.bz2 trackermap-server-3b5c04b4ddf71223371815575fa1b652fea1d5da.zip |
Handle modern app paths
Diffstat (limited to 'src/main/java/org/traccar/web/WebServer.java')
-rw-r--r-- | src/main/java/org/traccar/web/WebServer.java | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/main/java/org/traccar/web/WebServer.java b/src/main/java/org/traccar/web/WebServer.java index 0ed5d013e..9af9fd33a 100644 --- a/src/main/java/org/traccar/web/WebServer.java +++ b/src/main/java/org/traccar/web/WebServer.java @@ -68,16 +68,17 @@ import java.io.File; import java.io.IOException; import java.io.Writer; import java.net.InetSocketAddress; +import java.nio.file.Files; +import java.nio.file.Paths; import java.util.EnumSet; public class WebServer implements LifecycleObject { private static final Logger LOGGER = LoggerFactory.getLogger(WebServer.class); - private Server server; - - private void initServer(Config config) { + private final Server server; + public WebServer(Config config) { String address = config.getString(Keys.WEB_ADDRESS); int port = config.getInteger(Keys.WEB_PORT); if (address == null) { @@ -85,11 +86,6 @@ public class WebServer implements LifecycleObject { } else { server = new Server(new InetSocketAddress(address, port)); } - } - - public WebServer(Config config) { - - initServer(config); ServletContextHandler servletHandler = new ServletContextHandler(ServletContextHandler.SESSIONS); @@ -106,8 +102,13 @@ public class WebServer implements LifecycleObject { @Override protected void handleErrorPage( HttpServletRequest request, Writer writer, int code, String message) throws IOException { - writer.write("<!DOCTYPE><html><head><title>Error</title></head><html><body>" - + code + " - " + HttpStatus.getMessage(code) + "</body></html>"); + if (code == HttpStatus.NOT_FOUND_404 && request.getPathInfo().startsWith("/modern")) { + writer.write(Files.readString( + Paths.get(config.getString(Keys.WEB_PATH), "modern", "index.html"))); + } else { + writer.write("<!DOCTYPE><html><head><title>Error</title></head><html><body>" + + code + " - " + HttpStatus.getMessage(code) + "</body></html>"); + } } }); |