Compare commits

...

7 commits

Author SHA1 Message Date
hirst 09a253f3cc updated .idea stuff 2024-05-27 17:22:29 +02:00
hirst 31dcb2abf5 redone maven project files 2024-05-27 17:22:09 +02:00
hirst a36c9d778b added dummy application 2024-05-27 17:21:49 +02:00
hirst 035eb6ffb2 added openAPI stuff 2024-05-27 17:21:08 +02:00
hirst a651681c67 renamed eurika to eureka 2024-05-27 17:19:57 +02:00
hirst c02b24e766 gateway actually works 2024-05-27 15:58:42 +02:00
hirst 8e3bba298f updated application.properties to application.yml 2024-05-27 15:57:18 +02:00
23 changed files with 344 additions and 208 deletions

View file

@ -4,5 +4,7 @@
<file url="file://$PROJECT_DIR$/dummy/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/eureka/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/gateway/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component>
</project>

View file

@ -8,6 +8,7 @@
<option value="$PROJECT_DIR$/eurika/pom.xml" />
<option value="$PROJECT_DIR$/gateway/pom.xml" />
<option value="$PROJECT_DIR$/eureka/pom.xml" />
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>

View file

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/server.iml" filepath="$PROJECT_DIR$/.idea/server.iml" />
</modules>
</component>
</project>

View file

@ -3,20 +3,56 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.5</version>
<relativePath/> <!-- lookup parent from repository -->
<groupId>com.learningpulse</groupId>
<artifactId>server</artifactId>
<version>0.0.1</version>
</parent>
<groupId>com.learningpulse</groupId>
<artifactId>dummy</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.0.1</version>
<name>dummy</name>
<description>Demo project for Spring Boot</description>
<description>A dummy project</description>
<properties>
<java.version>22</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.security.oauth/spring-security-oauth2 -->
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<version>2.5.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-resource-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
@ -27,16 +63,6 @@
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
@ -44,21 +70,4 @@
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>

View file

@ -2,8 +2,11 @@ package com.learningpulse.dummy;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@SpringBootApplication
@EnableDiscoveryClient
public class DummyApplication {
public static void main(String[] args) {

View file

@ -0,0 +1,16 @@
package com.learningpulse.dummy;
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;
@RestController
@RequestMapping("/api/v1/dummy")
public class Test {
@GetMapping("/test")
public ResponseEntity<String> test() {
return ResponseEntity.ok("Hello, World!");
}
}

View file

@ -0,0 +1,2 @@
app:
eureka-server: eureka

View file

@ -1 +0,0 @@
spring.application.name=dummy

View file

@ -0,0 +1,36 @@
app:
eureka-server: localhost
server:
port: 0
spring:
application:
name: dummy
# TODO remove after testing
security:
user:
name: admin
password: admin
springdoc:
enable-native-support: true
api-docs:
enabled: true
path: /api/v1/dummy/v3/api-docs
swagger-ui:
path: /api/v1/dummy/swagger-ui.html
management:
endpoints:
web:
exposure:
include: "*"
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka
# Will only work when docker is used
# defaultZone: http://${app.eureka-server}:8761/eureka

View file

@ -3,20 +3,17 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.5</version>
<relativePath/> <!-- lookup parent from repository -->
<groupId>com.learningpulse</groupId>
<artifactId>server</artifactId>
<version>0.0.1</version>
</parent>
<groupId>com.learningpulse</groupId>
<artifactId>eureka</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.0.1</version>
<name>eureka</name>
<description>Demo project for Spring Boot</description>
<description>Eureka discovery server for LearningPulse</description>
<properties>
<java.version>22</java.version>
<spring-cloud.version>2023.0.1</spring-cloud.version>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-netflix-eureka-server -->
<dependency>
@ -24,33 +21,6 @@
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
<version>4.1.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View file

@ -1,4 +1,4 @@
package com.learningpulse.eurika;
package com.learningpulse.eureka;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

View file

@ -1,10 +0,0 @@
spring.application.name=eureka
server.port=8761
spring.security.user.name=admin
spring.security.user.password=admin
eureka.instance.hostname=localhost
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false

View file

@ -0,0 +1,18 @@
server:
port: 8761
eureka:
client:
register-with-eureka: false
fetch-registry: false
instance:
hostname: localhost
spring:
application:
name: eureka
security:
# TODO remove after testing
user:
name: admin
password: admin

View file

@ -1,4 +1,4 @@
package com.learningpulse.eurika;
package com.learningpulse.eureka;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

View file

@ -3,75 +3,49 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.5</version>
<groupId>com.learningpulse</groupId>
<artifactId>server</artifactId>
<version>0.0.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.learningpulse</groupId>
<artifactId>gateway</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.0.1</version>
<name>gateway</name>
<description>Demo project for Spring Boot</description>
<description>API gateway for LearningPulse</description>
<properties>
<java.version>22</java.version>
<spring-cloud.version>2023.0.1</spring-cloud.version>
</properties>
<!-- TODO bad dependencies here, CHANGE cus:
https://stackoverflow.com/questions/68587832/spring-cloud-gateway-spring-mvc-found-on-classpath-which-is-incompatible-with
TLDR: spring-cloud-starter-gateway-mvc is not compatible with eureka server (spring-cloud-starter-gateway)
-->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-circuitbreaker-reactor-resilience4j</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway-mvc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-mockmvc</artifactId>
<scope>test</scope>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<artifactId>springdoc-openapi-starter-webflux-ui</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
@ -100,18 +74,6 @@
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>

View file

@ -3,10 +3,11 @@ package com.learningpulse.gateway;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity;
@EnableDiscoveryClient
@SpringBootApplication
@EnableWebFluxSecurity
@EnableDiscoveryClient
public class GatewayApplication {
public static void main(String[] args) {

View file

@ -1,14 +0,0 @@
package com.learningpulse.gateway;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.function.RouterFunction;
import org.springframework.web.servlet.function.ServerResponse;
import static org.springframework.web.servlet.function.RouterFunctions.route;
import static org.springframework.cloud.gateway.server.mvc.handler.HandlerFunctions.http;
public class SimpleGateway {
@Bean
public RouterFunction<ServerResponse> getRoute() {
return route().GET("/get", http("https://httpbin.org")).build();
}
}

View file

@ -1,15 +0,0 @@
package com.learningpulse.gateway.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.function.RouterFunction;
import org.springframework.web.servlet.function.ServerResponse;
import org.springframework.web.servlet.function.RouterFunctions;
// TODO copy lambda code lol
@Configuration(proxyBeanMethods = false)
public class Appconfig {
}

View file

@ -0,0 +1,25 @@
package com.learningpulse.gateway.config;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
@Component
@Configuration
public class OpenAPIConfiguration {
@Bean
public OpenAPI gatewayOpenAPI() {
return new OpenAPI().info(new Info()
.title("Learning Pulse API documentation")
.version("0.0.1")
.description("This is the API documentation for the Learning Pulse project.")
.contact(new Contact()
.name("Learning Pulse")
.url("https://git.4o1x5.dev/LearningPulse"))
);
}
}

View file

@ -0,0 +1,2 @@
app:
eureka-server: eureka

View file

@ -1,25 +0,0 @@
spring.application.name=gateway
app.eureka-server=localhost
eureka.client.service-url.defaultZone=http://localhost:8761/eureka
server.port=8181
server.servlet.context-path=/
spring.cloud.discovery.enabled=true
# TODO change these back to lambda's stuffs
spring.cloud.gateway.mvc.routes[0].id=discovery-server
spring.cloud.gateway.mvc.routes[0].uri=http://${app.eureka-server}:8761
spring.cloud.gateway.mvc.routes[0].predicates[0]=Path=/eureka/web
spring.cloud.gateway.mvc.routes[0].filters[0]=SetPath=/
springdoc.enable-javadoc=true
springdoc.api-docs.enabled=true
springdoc.api-docs.groups.enabled=true
springdoc.swagger-ui.enabled=true
springdoc.swagger-ui.path=/swagger-ui.html
springdoc.swagger-ui.config-url=/v3/api-docs/swagger-config
springdoc.swagger-ui.urls[0].name=Api Gateway APIs
springdoc.swagger-ui.urls[0].url=/v3/api-docs

View file

@ -0,0 +1,81 @@
server:
port: 8181
spring:
application:
name: gateway
cloud:
gateway:
discovery:
locator:
enabled: true
routes:
# eureka service routing
- id: eureka
# Will only work when docker is used
# uri: http://${app.eureka-server}:8761
uri: http://localhost:8761
predicates:
- Path=/eureka/web
filters:
- SetPath=/
- id: eureka-static
# Will only work when docker is used
# uri: http://${app.eureka-server}:8761
uri: http://localhost:8761
predicates:
- Path=/eureka/**
# dummy service routing
# TODO smth is wrong with this
- id: dummy
uri: lb://dummy
predicates:
- Path=/api/v1/dummy/**
filters:
- AddResponseHeader=X-Powered-By, LearningPulse Gateway Service
security:
user:
name: admin
password: admin
# Keycloak configuration for the future
# security:
# oauth2:
# resourceserver:
# jwt:
# issuer-uri: ${KEYCLOAK_URL}/realms/LearningPulse
management:
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: always
gateway:
enabled: true
springdoc:
enable-native-support: true
api-docs:
enabled: true
groups:
enabled: true
swagger-ui:
path: /swagger-ui.html
config-url: /v3/api-docs/swagger-config
urls:
- name: Gateway API
url: /v3/api-docs
# TODO not working rn
- name: Dummy Service API
url: /api/v1/dummy/v3/api-docs
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka
# Will only work when docker is used
# defaultZone: http://${app.eureka-server}:8761/eureka

81
pom.xml Normal file
View file

@ -0,0 +1,81 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.learningpulse</groupId>
<artifactId>server</artifactId>
<version>0.0.1</version>
<packaging>pom</packaging>
<name>server</name>
<description>API server for LearningPulse</description>
<modules>
<module>gateway</module>
<module>eureka</module>
<module>dummy</module>
</modules>
<properties>
<java.version>22</java.version>
<maven.compiler.source>22</maven.compiler.source>
<maven.compiler.target>22</maven.compiler.target>
<spring-cloud.version>2023.0.1</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jetbrains/annotations -->
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>24.1.0</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>