Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
dima767 committed Jan 23, 2020
1 parent bb61c9b commit bd910bc
Showing 1 changed file with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,34 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.util.StreamUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.Charset;

@Controller
public class RootUiViewController {

@Value("classpath:/resources/index.html")
Resource resourceFile;
Resource indexHtmlResource;

@RequestMapping("/")
@ResponseBody
public void index(HttpServletRequest request, OutputStream os) throws IOException {
//@ResponseBody
public void index(HttpServletRequest request, HttpServletResponse response) throws IOException {
//TODO: Use Jsoup lib to inject context path into DOM before writing to response buffer

final String ctxPath = request.getContextPath();
try {
byte[] indexHtmlBytes = ByteStreams.toByteArray(resourceFile.getInputStream());
os.write(indexHtmlBytes, 0, indexHtmlBytes.length);
//os.write(ctxPath.getBytes(), 0, ctxPath.length());
}
finally {
os.close();
}

//This does not work! In order form Angular to kick in we need to redirect to index.html
String indexHtmlAsString = StreamUtils.copyToString(indexHtmlResource.getInputStream(), Charset.defaultCharset());
//byte[] indexHtmlBytes = ByteStreams.toByteArray(indexHtmlResource.getInputStream());
response.setHeader("Content-Type", "text/html");
response.getWriter().print(indexHtmlAsString);
//os.write(ctxPath.getBytes(), 0, ctxPath.length());
}
}

0 comments on commit bd910bc

Please sign in to comment.