Skip to content

Commit e490462

Browse files
committed
feat(homepage): Add the homepage
1 parent 82cb024 commit e490462

File tree

3 files changed

+97
-1
lines changed

3 files changed

+97
-1
lines changed

src/main/java/kz/ncanode/NCANode.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static void main(String[] args) {
1717
System.out.println(banner());
1818
SpringApplication.run(NCANode.class, args);
1919
}
20-
private static String banner() {
20+
public static String banner() {
2121
return """
2222
____ _____ ______ _ ____ _____ __ ______ \s
2323
|_ \\|_ _|.' ___ | / \\ |_ \\|_ _| | ] / ____ `.\s
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package kz.ncanode.controller;
2+
3+
import kz.ncanode.NCANode;
4+
import kz.ncanode.service.MaintenanceService;
5+
import lombok.RequiredArgsConstructor;
6+
import org.springframework.beans.factory.annotation.Value;
7+
import org.springframework.core.io.Resource;
8+
import org.springframework.http.MediaType;
9+
import org.springframework.stereotype.Controller;
10+
import org.springframework.util.FileCopyUtils;
11+
import org.springframework.web.bind.annotation.RequestMapping;
12+
import org.springframework.web.bind.annotation.ResponseBody;
13+
14+
import java.io.IOException;
15+
import java.io.InputStreamReader;
16+
import java.io.Reader;
17+
import java.io.UncheckedIOException;
18+
import java.nio.charset.StandardCharsets;
19+
20+
@Controller
21+
@RequiredArgsConstructor
22+
public class HomePageController {
23+
private final MaintenanceService maintenanceService;
24+
25+
@Value("classpath:home.html")
26+
private Resource homePage;
27+
@RequestMapping(value = "/", produces = MediaType.TEXT_HTML_VALUE)
28+
@ResponseBody
29+
public String homePage() {
30+
return loadHtml()
31+
.replace(variable("VERSION"), maintenanceService.getNCANodeVersion())
32+
.replace(variable("BANNER"), NCANode.banner());
33+
}
34+
35+
private String loadHtml() {
36+
try (Reader reader = new InputStreamReader(homePage.getInputStream(), StandardCharsets.UTF_8)) {
37+
return FileCopyUtils.copyToString(reader);
38+
} catch (IOException e) {
39+
throw new UncheckedIOException(e);
40+
}
41+
}
42+
43+
private static String variable(String name) {
44+
return String.format("#{%s}", name);
45+
}
46+
}

src/main/resources/home.html

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<!DOCTYPE html>
2+
<html dir="ltr">
3+
<head>
4+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5+
<meta charset="UTF-8">
6+
7+
<style type="text/css">
8+
body {
9+
background-color: #d1dce0;
10+
font-family: sans-serif;
11+
font-size: 14px;
12+
}
13+
14+
.content {
15+
display: flex;
16+
flex-direction: column;
17+
align-items: center;
18+
}
19+
20+
.version, .links {
21+
margin-top: 10px;
22+
}
23+
</style>
24+
25+
<title>NCANode v#{VERSION}</title>
26+
</head>
27+
<body>
28+
<div class="content">
29+
<pre>#{BANNER}</pre>
30+
31+
<div class="version">
32+
v#{VERSION}
33+
</div>
34+
35+
<div class="links">
36+
<a href="https://v3.ncanode.kz/docs/" target="_blank">
37+
docs
38+
</a>
39+
<span>|</span>
40+
<a href="https://v3.ncanode.kz/swagger-ui/" target="_blank">
41+
swagger
42+
</a>
43+
<span>|</span>
44+
<a href="https://github.com/malikzh/NCANode" target="_blank">
45+
github
46+
</a>
47+
</div>
48+
</div>
49+
</body>
50+
</html>

0 commit comments

Comments
 (0)