Skip to content

Commit

Permalink
chore: profile check (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
djdongjae committed Apr 8, 2024
1 parent 4c7d72b commit 6fb0775
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<String> profiles = Arrays.asList(env.getActiveProfiles());
List<String> realProfiles = Arrays.asList("real", "real1", "real2");
String defaultProfile = profiles.isEmpty() ? "default" : profiles.get(0);

return profiles.stream()
.filter(realProfiles::contains)
.findAny()
.orElse(defaultProfile);
}
}
2 changes: 2 additions & 0 deletions src/main/resources/application-real1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
server:
port: 8081
2 changes: 2 additions & 0 deletions src/main/resources/application-real2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
server:
port: 8082

0 comments on commit 6fb0775

Please sign in to comment.