Compare commits

..

No commits in common. "09a253f3ccf843995adbbb7872072b8fdda76fb3" and "45f52ab941c017fa833eb8957321def41c1cc05a" have entirely different histories.

23 changed files with 214 additions and 350 deletions

View file

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

View file

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

8
.idea/modules.xml Normal file
View file

@ -0,0 +1,8 @@
<?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,56 +3,20 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 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> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>com.learningpulse</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>server</artifactId> <artifactId>spring-boot-starter-parent</artifactId>
<version>0.0.1</version> <version>3.2.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent> </parent>
<groupId>com.learningpulse</groupId>
<artifactId>dummy</artifactId> <artifactId>dummy</artifactId>
<version>0.0.1</version> <version>0.0.1-SNAPSHOT</version>
<name>dummy</name> <name>dummy</name>
<description>A dummy project</description> <description>Demo project for Spring Boot</description>
<properties> <properties>
<java.version>22</java.version>
</properties> </properties>
<dependencies> <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> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId> <artifactId>spring-boot-starter-security</artifactId>
@ -63,6 +27,16 @@
<artifactId>postgresql</artifactId> <artifactId>postgresql</artifactId>
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </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> <dependency>
<groupId>org.springframework.security</groupId> <groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId> <artifactId>spring-security-test</artifactId>
@ -70,4 +44,21 @@
</dependency> </dependency>
</dependencies> </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> </project>

View file

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

View file

@ -1,16 +0,0 @@
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

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

View file

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

View file

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

View file

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

View file

@ -0,0 +1,10 @@
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

@ -1,18 +0,0 @@
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.eureka; package com.learningpulse.eurika;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;

View file

@ -3,49 +3,75 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 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> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>com.learningpulse</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>server</artifactId> <artifactId>spring-boot-starter-parent</artifactId>
<version>0.0.1</version> <version>3.2.5</version>
<relativePath/> <!-- lookup parent from repository --> <relativePath/> <!-- lookup parent from repository -->
</parent> </parent>
<groupId>com.learningpulse</groupId>
<artifactId>gateway</artifactId> <artifactId>gateway</artifactId>
<version>0.0.1</version> <version>0.0.1-SNAPSHOT</version>
<name>gateway</name> <name>gateway</name>
<description>API gateway for LearningPulse</description> <description>Demo project for Spring Boot</description>
<properties> <properties>
<java.version>22</java.version>
<spring-cloud.version>2023.0.1</spring-cloud.version>
</properties> </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> <dependencies>
<dependency>
<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</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-webflux-ui</artifactId>
<version>2.2.0</version>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-resource-server</artifactId> <artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> <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>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.2.0</version>
</dependency> </dependency>
</dependencies> </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> <build>
<plugins> <plugins>
@ -74,6 +100,18 @@
</dependency> </dependency>
</dependencies> </dependencies>
</plugin> </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> </plugins>
</build> </build>

View file

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

View file

@ -0,0 +1,14 @@
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

@ -0,0 +1,15 @@
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

@ -1,25 +0,0 @@
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

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

View file

@ -0,0 +1,25 @@
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

@ -1,81 +0,0 @@
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
View file

@ -1,81 +0,0 @@
<?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>