Skip to content

Commit

Permalink
refactor: #386 프로덕션 환경의 FCM 설정과 로컬 환경의 FCM 분리 (#393)
Browse files Browse the repository at this point in the history
* refactor: production 환경에서의 FCM Configuration 클래스 네이밍 변경 및 profile 설정 추가

* refactor: local 환경에서의 FCM Configuration 클래스 추가
  • Loading branch information
apptie authored and swonny committed Oct 6, 2023
1 parent 7599af5 commit fde1aab
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.ddang.ddang.configuration.fcm;

import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import com.google.firebase.messaging.FirebaseMessaging;
import java.util.List;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

@Configuration
@Profile("local")
public class LocalFcmConfiguration {

@Bean
public FirebaseMessaging firebaseMessaging() {
final FirebaseApp firebaseApps = findFirebaseApps();

return FirebaseMessaging.getInstance(firebaseApps);
}

private FirebaseApp findFirebaseApps() {
final List<FirebaseApp> apps = FirebaseApp.getApps();

if (!apps.isEmpty()) {
for (final FirebaseApp app : apps) {
if (FirebaseApp.DEFAULT_APP_NAME.equals(app.getName())) {
return app;
}
}
}

final FirebaseOptions options = FirebaseOptions.builder()
.setCredentials(new MockGoogleCredentials("test-token"))
.setProjectId("test-project")
.build();

return FirebaseApp.initializeApp(options);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import org.springframework.context.annotation.Profile;

@Configuration
@Profile("!test")
public class FcmConfiguration {
@Profile("!test && !local")
public class ProdFcmConfiguration {

@Value("${fcm.key.path}")
private String FCM_PRIVATE_KEY_PATH;
Expand Down

0 comments on commit fde1aab

Please sign in to comment.