Added version display
- Added error route handling
This commit is contained in:
parent
5a36b62bde
commit
9ca76948df
@ -40,6 +40,9 @@ dependencies {
|
||||
|
||||
bootJar {
|
||||
manifest {
|
||||
attributes(
|
||||
'Application-Version': project.version
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,11 +15,15 @@
|
||||
</div>
|
||||
<div class="grid grid-cols-1 sm:grid-cols-4 items-center gap-4 hover:scale-125 transition-transform duration-100">
|
||||
<h3 class="font-semibold text-gray-800 sm:col-span-2 md:text-right">Version:</h3>
|
||||
<p class="text-gray-800 sm:col-span-2 sm:text-left">1.0.0</p>
|
||||
<p class="text-gray-800 sm:col-span-2 sm:text-left">
|
||||
<span class="loading loading-spinner loading-md" *ngIf="!version"></span>
|
||||
<span *ngIf="version">{{ version }}</span>
|
||||
</p>
|
||||
</div>
|
||||
<div class="grid grid-cols-1 sm:grid-cols-4 items-center gap-4 hover:scale-125 transition-transform duration-100">
|
||||
<h3 class="font-semibold text-gray-800 sm:col-span-2 md:text-right">API-Status:</h3>
|
||||
<p class="sm:col-span-2 sm:text-left text-green-600">online</p>
|
||||
<span class="loading loading-spinner loading-md" *ngIf="!version"></span>
|
||||
<p class="sm:col-span-2 sm:text-left text-green-600" *ngIf="version">online</p>
|
||||
</div>
|
||||
<div class="grid grid-cols-1 sm:grid-cols-4 items-center gap-4 hover:scale-125 transition-transform duration-100">
|
||||
<h3 class=" font-semibold text-gray-800 sm:col-span-2 md:text-right">Libraries:</h3>
|
||||
|
@ -1,19 +1,26 @@
|
||||
import { Component } from '@angular/core';
|
||||
import {RouterLink} from "@angular/router";
|
||||
import {LegalService} from "../../service/legalService";
|
||||
import axios from "axios";
|
||||
import {DevelopmentStore} from "../../store/DevelopmentStore";
|
||||
import {NgIf} from "@angular/common";
|
||||
|
||||
@Component({
|
||||
selector: 'app-credits',
|
||||
standalone: true,
|
||||
imports: [
|
||||
RouterLink
|
||||
RouterLink,
|
||||
NgIf
|
||||
],
|
||||
templateUrl: './credits.component.html',
|
||||
styleUrl: './credits.component.scss'
|
||||
})
|
||||
export class CreditsComponent {
|
||||
|
||||
constructor(private legalService: LegalService) {
|
||||
version: string = '';
|
||||
|
||||
constructor(private legalService: LegalService, private developmentStore: DevelopmentStore) {
|
||||
this.getVersion();
|
||||
}
|
||||
|
||||
openPrivacyPolicyModal() {
|
||||
@ -23,4 +30,14 @@ export class CreditsComponent {
|
||||
openTermsOfUseModal() {
|
||||
this.legalService.openTermsOfUse();
|
||||
}
|
||||
|
||||
getVersion() {
|
||||
axios.get(this.developmentStore.getBaseUrl() + 'api/v1/version')
|
||||
.then((response) => {
|
||||
this.version = response.data;
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
package de.w665.sharepulse.rest;
|
||||
|
||||
import org.springframework.boot.web.servlet.error.ErrorController;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* This class is used to redirect the user to the home page if an endpoint is not found.
|
||||
*/
|
||||
@RestController
|
||||
public class ErrorRestController implements ErrorController {
|
||||
@RequestMapping("/error")
|
||||
public String handleError() {
|
||||
return "<script>" +
|
||||
"console.log('Page not found. Redirecting to /home...');" +
|
||||
"window.location.href = window.location.origin + '/home';" +
|
||||
"</script>";
|
||||
}
|
||||
}
|
37
src/main/java/de/w665/sharepulse/rest/mappings/Version.java
Normal file
37
src/main/java/de/w665/sharepulse/rest/mappings/Version.java
Normal file
@ -0,0 +1,37 @@
|
||||
package de.w665.sharepulse.rest.mappings;
|
||||
|
||||
import com.rethinkdb.net.Response;
|
||||
import de.w665.sharepulse.rest.ApiRestController;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.jar.Attributes;
|
||||
import java.util.jar.Manifest;
|
||||
|
||||
@RestController
|
||||
public class Version extends ApiRestController {
|
||||
|
||||
private final ResourceLoader resourceLoader;
|
||||
|
||||
@Autowired
|
||||
public Version(ResourceLoader resourceLoader) {
|
||||
this.resourceLoader = resourceLoader;
|
||||
}
|
||||
|
||||
@GetMapping("/version")
|
||||
public ResponseEntity<Object> getVersion() throws Exception {
|
||||
Resource resource = resourceLoader.getResource("classpath:META-INF/MANIFEST.MF");
|
||||
Manifest manifest = new Manifest(resource.getInputStream());
|
||||
Attributes attr = manifest.getMainAttributes();
|
||||
String version = attr.getValue("Application-Version");
|
||||
String response = version != null ? version : "Version is only available in production builds";
|
||||
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user