Skip to content

FCM Push Message Test Server - πŸš€ Simple Firebase Cloud Messaging (FCM) testing tool for Android & iOS Test push notifications with an easy web interface - just add your FCM service account and tokens!

Notifications You must be signed in to change notification settings

stevey-sy/push_test_server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Push Message Test Server

Quick Start: All you need are your Firebase Service Account JSON file and FCM tokens to start testing!

A simple Express-based server for testing push notifications to Android/iOS devices using Firebase Cloud Messaging (FCM).

ν•œκ΅­μ–΄ 버전 보기 (View Korean Version)


Features

  • πŸš€ Simple web interface for sending push notifications
  • πŸ“± Support for multiple FCM tokens
  • πŸ”„ Send multiple messages per token (bulk testing)
  • ✏️ Customizable message JSON (notification, data, android/ios specific settings)
  • πŸ“Š Detailed response with success/failure counts
  • 🎯 Perfect for testing push notification implementations

Prerequisites

To use this server, you only need two things:

  1. Firebase Service Account JSON file - Get it from your Firebase Console
  2. FCM Device Tokens - Get these from your mobile app

That's it! No complex setup required.

Installation

npm install

Firebase Service Account Setup

How to Get Your Firebase Service Account Key

  1. Go to Firebase Console
  2. Select your project
  3. Go to Project Settings > Service Accounts tab
  4. Click "Generate New Private Key" to download the JSON file
  5. Save the JSON file securely

Environment Variable Setup

Create a .env file in the project root and configure your Firebase credentials using one of the following methods:

Method 1: JSON file path (Recommended for local development)

FIREBASE_SERVICE_ACCOUNT_PATH=./path/to/your-firebase-service-account.json

Method 2: Complete JSON as string (Good for deployment)

FIREBASE_SERVICE_ACCOUNT='{"type":"service_account","project_id":"your-project-id","private_key":"-----BEGIN PRIVATE KEY-----\n...","client_email":"firebase-adminsdk-xxxxx@your-project-id.iam.gserviceaccount.com",...}'

Method 3: Individual fields (Most secure for production)

FIREBASE_PROJECT_ID=your-project-id
FIREBASE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\nYour private key here\n-----END PRIVATE KEY-----\n"
FIREBASE_CLIENT_EMAIL=firebase-adminsdk-xxxxx@your-project-id.iam.gserviceaccount.com

Running the Server

# Standard mode
npm start

# Development mode (with nodemon)
npm run dev

The server will start on http://localhost:3000 (or the PORT specified in your .env file).

Usage

Web Interface

  1. Open your browser and go to http://localhost:3000
  2. Enter one or more FCM device tokens
  3. (Optional) Customize the message JSON
  4. Set the number of messages to send per token
  5. Click "Send" button

Visual Guide

Step 1: Enter FCM Tokens

Main Interface

  • Enter your FCM device tokens (supports multiple tokens)
  • Set the number of messages to send per token (default: 10)
  • Optionally expand "Customize Message JSON" section to customize your push notification

Step 2: Customize Message (Optional)

Message Customization

  • Edit the JSON to customize notification title, body, and data fields
  • Use the "FORMAT" button to format your JSON
  • Use "RESET TO DEFAULT" to restore the default template
  • Use "LOAD EXAMPLE" to see a data-rich example
  • Click "SEND" when ready

API Endpoints

1. Health Check

GET /health

Check if the server and FCM are properly initialized.

Response:

{
  "status": "ok",
  "fcmInitialized": true,
  "timestamp": "2024-01-01T00:00:00.000Z"
}

2. Get Default Message Template

GET /message-template

Returns the default message template used by the server.

3. Send Push Messages

POST /push
Content-Type: application/json

Request Body:

{
  "tokens": ["token1", "token2"],
  "messagesPerToken": 10,
  "message": {
    "notification": {
      "title": "Test Notification",
      "body": "This is a test message"
    },
    "data": {
      "key1": "value1",
      "key2": "value2"
    },
    "android": {
      "priority": "high",
      "notification": {
        "sound": "default",
        "channelId": "default"
      }
    }
  }
}

Parameters:

  • tokens (required): Array of FCM device tokens
  • messagesPerToken (optional): Number of messages to send per token (default: 10, max: 100)
  • message (optional): Custom message object. If not provided, uses default template.

Success Response:

{
  "success": true,
  "summary": {
    "totalTokens": 2,
    "messagesPerToken": 10,
    "totalMessages": 20,
    "successCount": 20,
    "failureCount": 0
  },
  "results": [
    {
      "token": "token1",
      "messageIndex": 1,
      "success": true,
      "messageId": "0:1234567890",
      "error": null
    }
  ],
  "sentAt": "2024-01-01T00:00:00.000Z"
}

Message Customization

The message object in the request body supports all FCM message properties:

  • notification: The notification to show to the user

    • title: Notification title
    • body: Notification body text
  • data: Custom key-value pairs (all values will be converted to strings)

    • Use this to send custom data to your app
    • Your app can handle this data even when in the background
  • android: Android-specific options

    • priority: Message priority ("high" or "normal")
    • notification.sound: Notification sound
    • notification.channelId: Android notification channel ID
  • apns: iOS-specific options

    • Configure iOS notification behavior

Testing Example

Using cURL

curl -X POST http://localhost:3000/push \
  -H "Content-Type: application/json" \
  -d '{
    "tokens": ["your-fcm-device-token"],
    "messagesPerToken": 5
  }'

Using JavaScript (fetch)

fetch('http://localhost:3000/push', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    tokens: ['your-fcm-device-token'],
    messagesPerToken: 5,
    message: {
      notification: {
        title: 'Custom Title',
        body: 'Custom message body'
      },
      data: {
        eventId: '12345',
        type: 'custom_event'
      }
    }
  })
})
.then(res => res.json())
.then(data => console.log(data));

Troubleshooting

FCM Not Initialized

  • Make sure your .env file is properly configured
  • Verify that your Firebase Service Account JSON is valid
  • Check that the file path (if using Method 1) is correct

Token Error

  • Verify that your FCM tokens are valid and not expired
  • Make sure tokens are from the same Firebase project
  • Check that your app is properly registered with FCM

Network Error

  • Ensure your server has internet connectivity
  • Check if your firewall is blocking outgoing connections
  • Verify that FCM services are not blocked

License

MIT


ν•œκ΅­μ–΄ 버전

ν΄λ¦­ν•˜μ—¬ ν•œκ΅­μ–΄ λ¬Έμ„œ 보기

Push Message Test Server

λΉ λ₯Έ μ‹œμž‘: ν…ŒμŠ€νŠΈλ₯Ό μœ„ν•΄ ν•„μš”ν•œ 것은 Firebase μ„œλΉ„μŠ€ 계정 JSON 파일과 FCM 토큰 λΏμž…λ‹ˆλ‹€!

Expressλ₯Ό μ‚¬μš©ν•œ Android/iOS 기기둜 ν‘Έμ‹œ μ•Œλ¦Όμ„ ν…ŒμŠ€νŠΈν•˜κΈ° μœ„ν•œ κ°„λ‹¨ν•œ μ„œλ²„μž…λ‹ˆλ‹€.

νŠΉμ§•

  • πŸš€ ν‘Έμ‹œ μ•Œλ¦Ό λ°œμ†‘μ„ μœ„ν•œ κ°„λ‹¨ν•œ μ›Ή μΈν„°νŽ˜μ΄μŠ€
  • πŸ“± 닀쀑 FCM 토큰 지원
  • πŸ”„ 토큰당 μ—¬λŸ¬ λ©”μ‹œμ§€ λ°œμ†‘ (λŒ€λŸ‰ ν…ŒμŠ€νŠΈ)
  • ✏️ μ»€μŠ€ν„°λ§ˆμ΄μ§• κ°€λŠ₯ν•œ λ©”μ‹œμ§€ JSON (notification, data, android/ios νŠΉμ • μ„€μ •)
  • πŸ“Š 성곡/μ‹€νŒ¨ κ°œμˆ˜κ°€ ν¬ν•¨λœ μƒμ„Έν•œ 응닡
  • 🎯 ν‘Έμ‹œ μ•Œλ¦Ό κ΅¬ν˜„ ν…ŒμŠ€νŠΈμ— 완벽함

ν•„μˆ˜ μš”κ΅¬μ‚¬ν•­

이 μ„œλ²„λ₯Ό μ‚¬μš©ν•˜κΈ° μœ„ν•΄ ν•„μš”ν•œ 것은 단 두 κ°€μ§€μž…λ‹ˆλ‹€:

  1. Firebase μ„œλΉ„μŠ€ 계정 JSON 파일 - Firebase μ½˜μ†”μ—μ„œ λ°œκΈ‰λ°›μœΌμ„Έμš”
  2. FCM λ””λ°”μ΄μŠ€ 토큰 - λͺ¨λ°”일 μ•±μ—μ„œ 얻을 수 μžˆμŠ΅λ‹ˆλ‹€

이것이 μ „λΆ€μž…λ‹ˆλ‹€! λ³΅μž‘ν•œ 섀정이 ν•„μš” μ—†μŠ΅λ‹ˆλ‹€.

μ„€μΉ˜ 방법

npm install

Firebase μ„œλΉ„μŠ€ 계정 μ„€μ •

Firebase μ„œλΉ„μŠ€ 계정 ν‚€ λ°œκΈ‰ 방법

  1. Firebase Console에 접속
  2. ν”„λ‘œμ νŠΈ 선택
  3. ν”„λ‘œμ νŠΈ μ„€μ • > μ„œλΉ„μŠ€ 계정 νƒ­μœΌλ‘œ 이동
  4. "μƒˆ λΉ„κ³΅κ°œ ν‚€ 생성" ν΄λ¦­ν•˜μ—¬ JSON 파일 λ‹€μš΄λ‘œλ“œ
  5. JSON νŒŒμΌμ„ μ•ˆμ „ν•˜κ²Œ 보관

ν™˜κ²½ λ³€μˆ˜ μ„€μ •

ν”„λ‘œμ νŠΈ λ£¨νŠΈμ— .env νŒŒμΌμ„ μƒμ„±ν•˜κ³  λ‹€μŒ 방법 쀑 ν•˜λ‚˜λ‘œ Firebase 인증 정보λ₯Ό μ„€μ •ν•˜μ„Έμš”:

방법 1: JSON 파일 경둜 (둜컬 κ°œλ°œμ— ꢌμž₯)

FIREBASE_SERVICE_ACCOUNT_PATH=./path/to/your-firebase-service-account.json

방법 2: JSON 전체λ₯Ό λ¬Έμžμ—΄λ‘œ (배포에 적합)

FIREBASE_SERVICE_ACCOUNT='{"type":"service_account","project_id":"your-project-id","private_key":"-----BEGIN PRIVATE KEY-----\n...","client_email":"firebase-adminsdk-xxxxx@your-project-id.iam.gserviceaccount.com",...}'

방법 3: κ°œλ³„ ν•„λ“œ (ν”„λ‘œλ•μ…˜μ—μ„œ κ°€μž₯ μ•ˆμ „)

FIREBASE_PROJECT_ID=your-project-id
FIREBASE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\nYour private key here\n-----END PRIVATE KEY-----\n"
FIREBASE_CLIENT_EMAIL=firebase-adminsdk-xxxxx@your-project-id.iam.gserviceaccount.com

μ„œλ²„ μ‹€ν–‰

# 일반 λͺ¨λ“œ
npm start

# 개발 λͺ¨λ“œ (nodemon μ‚¬μš©)
npm run dev

μ„œλ²„λŠ” http://localhost:3000μ—μ„œ μ‹œμž‘λ©λ‹ˆλ‹€ (.env νŒŒμΌμ— μ§€μ •λœ PORT μ‚¬μš©).

μ‚¬μš© 방법

μ›Ή μΈν„°νŽ˜μ΄μŠ€

  1. λΈŒλΌμš°μ €μ—μ„œ http://localhost:3000 접속
  2. ν•˜λ‚˜ μ΄μƒμ˜ FCM λ””λ°”μ΄μŠ€ 토큰 μž…λ ₯
  3. (선택사항) λ©”μ‹œμ§€ JSON μ»€μŠ€ν„°λ§ˆμ΄μ§•
  4. 토큰당 λ°œμ†‘ν•  λ©”μ‹œμ§€ 개수 μ„€μ •
  5. "λ°œμ‹ ν•˜κΈ°" λ²„νŠΌ 클릭

μ‹œκ°μ  κ°€μ΄λ“œ

1단계: FCM 토큰 μž…λ ₯

메인 μΈν„°νŽ˜μ΄μŠ€

  • FCM λ””λ°”μ΄μŠ€ 토큰 μž…λ ₯ (μ—¬λŸ¬ 토큰 지원)
  • 토큰당 λ°œμ†‘ν•  λ©”μ‹œμ§€ 개수 μ„€μ • (κΈ°λ³Έκ°’: 10)
  • μ„ νƒμ μœΌλ‘œ "λ©”μ‹œμ§€ JSON μ»€μŠ€ν„°λ§ˆμ΄μ§•" μ„Ήμ…˜μ„ νŽΌμ³μ„œ ν‘Έμ‹œ μ•Œλ¦Όμ„ μ»€μŠ€ν„°λ§ˆμ΄μ§•ν•  수 μžˆμŠ΅λ‹ˆλ‹€

2단계: λ©”μ‹œμ§€ μ»€μŠ€ν„°λ§ˆμ΄μ§• (선택사항)

λ©”μ‹œμ§€ μ»€μŠ€ν„°λ§ˆμ΄μ§•

  • JSON을 νŽΈμ§‘ν•˜μ—¬ μ•Œλ¦Ό 제λͺ©, λ³Έλ¬Έ, 데이터 ν•„λ“œλ₯Ό μ»€μŠ€ν„°λ§ˆμ΄μ§•
  • "ν¬λ§·νŒ…" λ²„νŠΌμ„ μ‚¬μš©ν•˜μ—¬ JSON 포맷 정리
  • "κΈ°λ³Έκ°’μœΌλ‘œ 리셋"을 μ‚¬μš©ν•˜μ—¬ κΈ°λ³Έ ν…œν”Œλ¦Ώ 볡원
  • "데이터 μ˜ˆμ‹œ λ‘œλ“œ"λ₯Ό μ‚¬μš©ν•˜μ—¬ 데이터가 ν’λΆ€ν•œ μ˜ˆμ‹œ 확인
  • μ€€λΉ„κ°€ 되면 "λ°œμ‹ ν•˜κΈ°" 클릭

API μ—”λ“œν¬μΈνŠΈ

1. ν—¬μŠ€ 체크

GET /health

μ„œλ²„μ™€ FCM이 μ œλŒ€λ‘œ μ΄ˆκΈ°ν™”λ˜μ—ˆλŠ”μ§€ ν™•μΈν•©λ‹ˆλ‹€.

응닡:

{
  "status": "ok",
  "fcmInitialized": true,
  "timestamp": "2024-01-01T00:00:00.000Z"
}

2. κΈ°λ³Έ λ©”μ‹œμ§€ ν…œν”Œλ¦Ώ κ°€μ Έμ˜€κΈ°

GET /message-template

μ„œλ²„μ—μ„œ μ‚¬μš©ν•˜λŠ” κΈ°λ³Έ λ©”μ‹œμ§€ ν…œν”Œλ¦Ώμ„ λ°˜ν™˜ν•©λ‹ˆλ‹€.

3. ν‘Έμ‹œ λ©”μ‹œμ§€ λ°œμ‹ 

POST /push
Content-Type: application/json

μš”μ²­ λ³Έλ¬Έ:

{
  "tokens": ["token1", "token2"],
  "messagesPerToken": 10,
  "message": {
    "notification": {
      "title": "ν…ŒμŠ€νŠΈ μ•Œλ¦Ό",
      "body": "ν…ŒμŠ€νŠΈ λ©”μ‹œμ§€μž…λ‹ˆλ‹€"
    },
    "data": {
      "key1": "value1",
      "key2": "value2"
    },
    "android": {
      "priority": "high",
      "notification": {
        "sound": "default",
        "channelId": "default"
      }
    }
  }
}

λ§€κ°œλ³€μˆ˜:

  • tokens (ν•„μˆ˜): FCM λ””λ°”μ΄μŠ€ 토큰 λ°°μ—΄
  • messagesPerToken (선택): 토큰당 λ°œμ†‘ν•  λ©”μ‹œμ§€ 개수 (κΈ°λ³Έκ°’: 10, μ΅œλŒ€: 100)
  • message (선택): μ»€μŠ€ν…€ λ©”μ‹œμ§€ 객체. μ œκ³΅ν•˜μ§€ μ•ŠμœΌλ©΄ κΈ°λ³Έ ν…œν”Œλ¦Ώ μ‚¬μš©.

성곡 응닡:

{
  "success": true,
  "summary": {
    "totalTokens": 2,
    "messagesPerToken": 10,
    "totalMessages": 20,
    "successCount": 20,
    "failureCount": 0
  },
  "results": [
    {
      "token": "token1",
      "messageIndex": 1,
      "success": true,
      "messageId": "0:1234567890",
      "error": null
    }
  ],
  "sentAt": "2024-01-01T00:00:00.000Z"
}

λ©”μ‹œμ§€ μ»€μŠ€ν„°λ§ˆμ΄μ§•

μš”μ²­ 본문의 message κ°μ²΄λŠ” λͺ¨λ“  FCM λ©”μ‹œμ§€ 속성을 μ§€μ›ν•©λ‹ˆλ‹€:

  • notification: μ‚¬μš©μžμ—κ²Œ ν‘œμ‹œν•  μ•Œλ¦Ό

    • title: μ•Œλ¦Ό 제λͺ©
    • body: μ•Œλ¦Ό λ³Έλ¬Έ ν…μŠ€νŠΈ
  • data: μ»€μŠ€ν…€ ν‚€-κ°’ 쌍 (λͺ¨λ“  값은 λ¬Έμžμ—΄λ‘œ λ³€ν™˜λ¨)

    • 앱에 μ»€μŠ€ν…€ 데이터λ₯Ό μ „μ†‘ν•˜λŠ” 데 μ‚¬μš©
    • 앱이 λ°±κ·ΈλΌμš΄λ“œ μƒνƒœμΌ λ•Œλ„ 이 데이터λ₯Ό μ²˜λ¦¬ν•  수 μžˆμŠ΅λ‹ˆλ‹€
  • android: Android νŠΉμ • μ˜΅μ…˜

    • priority: λ©”μ‹œμ§€ μš°μ„ μˆœμœ„ ("high" λ˜λŠ” "normal")
    • notification.sound: μ•Œλ¦Ό μ‚¬μš΄λ“œ
    • notification.channelId: Android μ•Œλ¦Ό 채널 ID
  • apns: iOS νŠΉμ • μ˜΅μ…˜

    • iOS μ•Œλ¦Ό λ™μž‘ ꡬ성

ν…ŒμŠ€νŠΈ μ˜ˆμ‹œ

cURL μ‚¬μš©

curl -X POST http://localhost:3000/push \
  -H "Content-Type: application/json" \
  -d '{
    "tokens": ["your-fcm-device-token"],
    "messagesPerToken": 5
  }'

JavaScript (fetch) μ‚¬μš©

fetch('http://localhost:3000/push', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    tokens: ['your-fcm-device-token'],
    messagesPerToken: 5,
    message: {
      notification: {
        title: 'μ»€μŠ€ν…€ 제λͺ©',
        body: 'μ»€μŠ€ν…€ λ©”μ‹œμ§€ λ³Έλ¬Έ'
      },
      data: {
        eventId: '12345',
        type: 'custom_event'
      }
    }
  })
})
.then(res => res.json())
.then(data => console.log(data));

문제 ν•΄κ²°

FCM이 μ΄ˆκΈ°ν™”λ˜μ§€ μ•ŠμŒ

  • .env 파일이 μ˜¬λ°”λ₯΄κ²Œ κ΅¬μ„±λ˜μ—ˆλŠ”μ§€ 확인
  • Firebase μ„œλΉ„μŠ€ 계정 JSON이 μœ νš¨ν•œμ§€ 확인
  • 파일 경둜(방법 1 μ‚¬μš© μ‹œ)κ°€ μ˜¬λ°”λ₯Έμ§€ 확인

토큰 였λ₯˜

  • FCM 토큰이 μœ νš¨ν•˜κ³  λ§Œλ£Œλ˜μ§€ μ•Šμ•˜λŠ”μ§€ 확인
  • 토큰듀이 같은 Firebase ν”„λ‘œμ νŠΈμ—μ„œ λ°œκΈ‰λ˜μ—ˆλŠ”μ§€ 확인
  • 앱이 FCM에 μ œλŒ€λ‘œ λ“±λ‘λ˜μ—ˆλŠ”μ§€ 확인

λ„€νŠΈμ›Œν¬ 였λ₯˜

  • μ„œλ²„κ°€ 인터넷에 μ—°κ²°λ˜μ–΄ μžˆλŠ”μ§€ 확인
  • 방화벽이 μ•„μ›ƒλ°”μš΄λ“œ 연결을 μ°¨λ‹¨ν•˜μ§€ μ•ŠλŠ”μ§€ 확인
  • FCM μ„œλΉ„μŠ€κ°€ μ°¨λ‹¨λ˜μ§€ μ•Šμ•˜λŠ”μ§€ 확인

λΌμ΄μ„ μŠ€

MIT

About

FCM Push Message Test Server - πŸš€ Simple Firebase Cloud Messaging (FCM) testing tool for Android & iOS Test push notifications with an easy web interface - just add your FCM service account and tokens!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published