Skip to content

Commit

Permalink
FIX : /tmp 에 fcm key 저장
Browse files Browse the repository at this point in the history
  • Loading branch information
gouyeonch committed Oct 30, 2024
1 parent 82ba4b7 commit 044785f
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/main/java/com/kkokkomu/short_news/core/config/FCMConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,29 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

@Configuration
public class FCMConfig {

@Bean
public FirebaseMessaging firebaseMessaging() throws IOException {
// 1. firebase_key.json을 ClassPath에서 로드
ClassPathResource resource = new ClassPathResource("firebase/firebase_service_key.json");
// 1. /tmp 경로에서 firebase_service_key.json 파일 로드
File firebaseKeyFile = new File("/tmp/firebase_service_key.json");

try (InputStream refreshToken = resource.getInputStream()) {
if (!firebaseKeyFile.exists()) {
throw new IllegalStateException("Firebase key file not found at /tmp/firebase_service_key.json");
}

try (FileInputStream refreshToken = new FileInputStream(firebaseKeyFile)) {
// 2. Firebase 앱 인스턴스가 이미 있는지 확인
List<FirebaseApp> firebaseApps = FirebaseApp.getApps();
FirebaseApp firebaseApp;

if (firebaseApps != null && !firebaseApps.isEmpty()) {
if (!firebaseApps.isEmpty()) {
// 기존 인스턴스가 있으면 재사용
firebaseApp = FirebaseApp.getInstance();
} else {
Expand Down

0 comments on commit 044785f

Please sign in to comment.