diff --git a/Dockerfile b/Dockerfile index 611dcd3..e054395 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,5 +9,5 @@ WORKDIR /opt/lbry/globe/ EXPOSE 25/tcp EXPOSE 465/tcp EXPOSE 587/tcp -COPY --from=build /tmp/target/lbry-globe-latest-jar-with-dependencies.jar ./lbry-globe.jar +COPY --from=build /tmp/target/lbry-globe-*-jar-with-dependencies.jar ./lbry-globe.jar CMD ["java","-jar","lbry-globe.jar"] \ No newline at end of file diff --git a/src/main/java/com/lbry/globe/handler/HTTPHandler.java b/src/main/java/com/lbry/globe/handler/HTTPHandler.java index c1a65a4..063c497 100644 --- a/src/main/java/com/lbry/globe/handler/HTTPHandler.java +++ b/src/main/java/com/lbry/globe/handler/HTTPHandler.java @@ -1,6 +1,7 @@ package com.lbry.globe.handler; import com.lbry.globe.api.API; + import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.ChannelHandlerContext; @@ -8,10 +9,10 @@ import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.handler.codec.http.*; import io.netty.util.AttributeKey; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.io.IOException; import java.net.URI; -import java.net.URL; -import java.nio.file.Files; -import java.nio.file.Paths; import java.util.*; @@ -53,7 +54,7 @@ public class HTTPHandler extends ChannelInboundHandlerAdapter{ int status = 200; byte[] indexData; try{ - indexData = Files.readAllBytes(Paths.get(HTTPHandler.getResource("index.html").toURI())); + indexData = HTTPHandler.readResource(HTTPHandler.getResource("index.html")); }catch(Exception ignored){ status = 500; indexData = "Some error occured.".getBytes(); @@ -79,7 +80,7 @@ public class HTTPHandler extends ChannelInboundHandlerAdapter{ } byte[] fileData = null; try{ - fileData = Files.readAllBytes(Paths.get(HTTPHandler.getResource(uri.getPath().substring(1)).toURI())); + fileData = HTTPHandler.readResource(HTTPHandler.getResource(uri.getPath().substring(1))); }catch(Exception ignored){ } boolean ok = fileData!=null; @@ -121,8 +122,18 @@ public class HTTPHandler extends ChannelInboundHandlerAdapter{ ctx.close(); } - private static URL getResource(String name){ - return HTTPHandler.class.getClassLoader().getResource(name); + private static byte[] readResource(InputStream in) throws IOException{ + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + int nRead; + byte[] data = new byte[16384]; + while ((nRead = in.read(data, 0, data.length)) != -1) { + buffer.write(data, 0, nRead); + } + return buffer.toByteArray(); + } + + private static InputStream getResource(String name){ + return HTTPHandler.class.getClassLoader().getResourceAsStream(name); } } \ No newline at end of file diff --git a/src/main/resources/index.html b/src/main/resources/index.html index e6a5167..0b28131 100644 --- a/src/main/resources/index.html +++ b/src/main/resources/index.html @@ -1,7 +1,12 @@ +
+ + + +