Fix getting resources
This commit is contained in:
parent
5c1381bdb1
commit
5a4f8f97b5
3 changed files with 24 additions and 8 deletions
|
@ -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"]
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,7 +1,12 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en" prefix="og: https://ogp.me/ns#">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta content="initial-scale=1,width=device-width" name="viewport" />
|
||||
<meta content="/favicon.ico" property="og:image" />
|
||||
<meta content="LBRY Globe" property="og:title" />
|
||||
<meta content="website" property="og:type" />
|
||||
<meta content="//globe.lbry.org" property="og:url" />
|
||||
<script src="//unpkg.com/globe.gl"></script>
|
||||
<style>
|
||||
body{
|
||||
|
|
Loading…
Add table
Reference in a new issue