-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
97 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/main/java/kz/ncanode/controller/HomePageController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package kz.ncanode.controller; | ||
|
||
import kz.ncanode.NCANode; | ||
import kz.ncanode.service.MaintenanceService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.core.io.Resource; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.util.FileCopyUtils; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.io.Reader; | ||
import java.io.UncheckedIOException; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
@Controller | ||
@RequiredArgsConstructor | ||
public class HomePageController { | ||
private final MaintenanceService maintenanceService; | ||
|
||
@Value("classpath:home.html") | ||
private Resource homePage; | ||
@RequestMapping(value = "/", produces = MediaType.TEXT_HTML_VALUE) | ||
@ResponseBody | ||
public String homePage() { | ||
return loadHtml() | ||
.replace(variable("VERSION"), maintenanceService.getNCANodeVersion()) | ||
.replace(variable("BANNER"), NCANode.banner()); | ||
} | ||
|
||
private String loadHtml() { | ||
try (Reader reader = new InputStreamReader(homePage.getInputStream(), StandardCharsets.UTF_8)) { | ||
return FileCopyUtils.copyToString(reader); | ||
} catch (IOException e) { | ||
throw new UncheckedIOException(e); | ||
} | ||
} | ||
|
||
private static String variable(String name) { | ||
return String.format("#{%s}", name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<!DOCTYPE html> | ||
<html dir="ltr"> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | ||
<meta charset="UTF-8"> | ||
|
||
<style type="text/css"> | ||
body { | ||
background-color: #d1dce0; | ||
font-family: sans-serif; | ||
font-size: 14px; | ||
} | ||
|
||
.content { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
} | ||
|
||
.version, .links { | ||
margin-top: 10px; | ||
} | ||
</style> | ||
|
||
<title>NCANode v#{VERSION}</title> | ||
</head> | ||
<body> | ||
<div class="content"> | ||
<pre>#{BANNER}</pre> | ||
|
||
<div class="version"> | ||
v#{VERSION} | ||
</div> | ||
|
||
<div class="links"> | ||
<a href="https://v3.ncanode.kz/docs/" target="_blank"> | ||
docs | ||
</a> | ||
<span>|</span> | ||
<a href="https://v3.ncanode.kz/swagger-ui/" target="_blank"> | ||
swagger | ||
</a> | ||
<span>|</span> | ||
<a href="https://github.com/malikzh/NCANode" target="_blank"> | ||
github | ||
</a> | ||
</div> | ||
</div> | ||
</body> | ||
</html> |