This project, rhangfhindel-back-end
, is a Node.js server application designed to handle notification services using Firebase Cloud Messaging (FCM). It registers device tokens, organizes them by generation, and sends notifications to the registered devices.
- Token Registration: Register device tokens along with a generation identifier.
- Token Retrieval: Retrieve all registered tokens.
- Token Clearing: Clear all registered tokens.
- Notification Sending: Send notifications to all devices or specific generations.
- Node.js
- Firebase Admin SDK
- Service account credentials for Firebase
- Environment variables set in a
.env
file
-
Clone the repository:
git clone https://github.com/nielxfb/rhangfhindel-back-end.git cd rhangfhindel-back-end
-
Install dependencies:
npm install
-
Copy the .env.example into a .env file:
cp .env.example .env
-
Place your Firebase service account credentials file in the root directory and name it
service-account-credentials.json
.
Start the server with the following command:
node index.js
The server will run on the port specified in the .env
file or default to port 3000.
Endpoint: /api/register-token
Method: POST
Description: Registers a device token with a generation identifier.
Request Body:
{
"token": "device_token",
"generation": "generation_identifier"
}
Responses:
200 OK
: Token received.400 Bad Request
: Token is missing, Generation is missing, Invalid generation format, or Token already registered.
Endpoint: /api/get-tokens
Method: GET
Description: Retrieves all registered tokens organized by generation.
Responses:
200 OK
: A JSON object containing tokens.
Endpoint: /api/clear-tokens
Method: POST
Description: Clears all registered tokens.
Responses:
200 OK
: Tokens cleared.
Endpoint: /api/send-notification
Method: POST
Description: Sends a notification to all devices or specific generation.
Request Body:
{
"title": "Notification Title",
"body": "Notification Body",
"onlyForGeneration": "generation_identifier" (optional)
}
Responses:
200 OK
: Notification sent.400 Bad Request
: Title is missing, Body is missing, Invalid generation format, or No tokens for this generation.500 Internal Server Error
: Failed to send notification.
This project is licensed under the MIT License. See the LICENSE
file for details.