From 6fb0775d19526139ea00bbe8fca61374b7eb36b8 Mon Sep 17 00:00:00 2001 From: djdongjae Date: Tue, 9 Apr 2024 00:34:30 +0900 Subject: [PATCH] chore: profile check (#7) --- .../controller/ProfileController.java | 27 +++++++++++++++++++ src/main/resources/application-real1.yml | 2 ++ src/main/resources/application-real2.yml | 2 ++ 3 files changed, 31 insertions(+) create mode 100644 src/main/java/net/skhu/tastyinventory_be/controller/ProfileController.java create mode 100644 src/main/resources/application-real1.yml create mode 100644 src/main/resources/application-real2.yml diff --git a/src/main/java/net/skhu/tastyinventory_be/controller/ProfileController.java b/src/main/java/net/skhu/tastyinventory_be/controller/ProfileController.java new file mode 100644 index 0000000..855763e --- /dev/null +++ b/src/main/java/net/skhu/tastyinventory_be/controller/ProfileController.java @@ -0,0 +1,27 @@ +package net.skhu.tastyinventory_be.controller; + +import lombok.RequiredArgsConstructor; +import org.springframework.core.env.Environment; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Arrays; +import java.util.List; + +@RequiredArgsConstructor +@RestController +public class ProfileController { + private final Environment env; + + @GetMapping("/profile") + public String profile() { + List profiles = Arrays.asList(env.getActiveProfiles()); + List realProfiles = Arrays.asList("real", "real1", "real2"); + String defaultProfile = profiles.isEmpty() ? "default" : profiles.get(0); + + return profiles.stream() + .filter(realProfiles::contains) + .findAny() + .orElse(defaultProfile); + } +} diff --git a/src/main/resources/application-real1.yml b/src/main/resources/application-real1.yml new file mode 100644 index 0000000..54b155f --- /dev/null +++ b/src/main/resources/application-real1.yml @@ -0,0 +1,2 @@ +server: + port: 8081 \ No newline at end of file diff --git a/src/main/resources/application-real2.yml b/src/main/resources/application-real2.yml new file mode 100644 index 0000000..0884131 --- /dev/null +++ b/src/main/resources/application-real2.yml @@ -0,0 +1,2 @@ +server: + port: 8082 \ No newline at end of file