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 25/tcp
|
||||||
EXPOSE 465/tcp
|
EXPOSE 465/tcp
|
||||||
EXPOSE 587/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"]
|
CMD ["java","-jar","lbry-globe.jar"]
|
|
@ -1,6 +1,7 @@
|
||||||
package com.lbry.globe.handler;
|
package com.lbry.globe.handler;
|
||||||
|
|
||||||
import com.lbry.globe.api.API;
|
import com.lbry.globe.api.API;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
@ -8,10 +9,10 @@ import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||||
import io.netty.handler.codec.http.*;
|
import io.netty.handler.codec.http.*;
|
||||||
import io.netty.util.AttributeKey;
|
import io.netty.util.AttributeKey;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URL;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,7 +54,7 @@ public class HTTPHandler extends ChannelInboundHandlerAdapter{
|
||||||
int status = 200;
|
int status = 200;
|
||||||
byte[] indexData;
|
byte[] indexData;
|
||||||
try{
|
try{
|
||||||
indexData = Files.readAllBytes(Paths.get(HTTPHandler.getResource("index.html").toURI()));
|
indexData = HTTPHandler.readResource(HTTPHandler.getResource("index.html"));
|
||||||
}catch(Exception ignored){
|
}catch(Exception ignored){
|
||||||
status = 500;
|
status = 500;
|
||||||
indexData = "Some error occured.".getBytes();
|
indexData = "Some error occured.".getBytes();
|
||||||
|
@ -79,7 +80,7 @@ public class HTTPHandler extends ChannelInboundHandlerAdapter{
|
||||||
}
|
}
|
||||||
byte[] fileData = null;
|
byte[] fileData = null;
|
||||||
try{
|
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){
|
}catch(Exception ignored){
|
||||||
}
|
}
|
||||||
boolean ok = fileData!=null;
|
boolean ok = fileData!=null;
|
||||||
|
@ -121,8 +122,18 @@ public class HTTPHandler extends ChannelInboundHandlerAdapter{
|
||||||
ctx.close();
|
ctx.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static URL getResource(String name){
|
private static byte[] readResource(InputStream in) throws IOException{
|
||||||
return HTTPHandler.class.getClassLoader().getResource(name);
|
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>
|
<!DOCTYPE html>
|
||||||
|
<html lang="en" prefix="og: https://ogp.me/ns#">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta content="initial-scale=1,width=device-width" name="viewport" />
|
<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>
|
<script src="//unpkg.com/globe.gl"></script>
|
||||||
<style>
|
<style>
|
||||||
body{
|
body{
|
||||||
|
|
Loading…
Add table
Reference in a new issue