From 3d3f6f2779887ee6a4427c9d15dd495693c57635 Mon Sep 17 00:00:00 2001 From: "seonkyu.kim" Date: Thu, 25 Jul 2024 13:56:28 +0900 Subject: [PATCH] =?UTF-8?q?[=F0=9F=91=B7]=20=EC=84=A4=EC=A0=95=20=EC=9E=91?= =?UTF-8?q?=EC=97=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/push.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ db/database.js | 16 ++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 apps/push.js create mode 100644 db/database.js diff --git a/apps/push.js b/apps/push.js new file mode 100644 index 0000000..4d35511 --- /dev/null +++ b/apps/push.js @@ -0,0 +1,45 @@ +import { admin } from '../firebaseConfig.js'; + +export function HandlePush(req, res) { + const { fcmToken, title, body, parameter, sound, badge } = req.body; + + if (!fcmToken || !title || !body) { + res.status(400).json({ error: 'fcmToken, title, body, and parameter are required' }); + return; + } + + const message = { + token: fcmToken, + notification: { + title: title, + body: body, + }, + apns: { + payload: { + aps: { + alert: { + title: title, + body: body, + parameter: parameter, + }, + sound: sound || 'default', + badge: badge ? Number(badge) : 0, + }, + }, + }, + }; + + + // const jjApp = admin.app('jjungtable'); + + admin.app('jjungtable').messaging().send(message) + .then((response) => { + console.log('Successfully sent message:', response); + res.status(200).json({ message: 'Successfully sent message' }); + }) + .catch((error) => { + console.error('Error sending message:', error); + res.status(500).json({ error: `Error sending message: ${error.message}` }); + }); +} + diff --git a/db/database.js b/db/database.js new file mode 100644 index 0000000..abae567 --- /dev/null +++ b/db/database.js @@ -0,0 +1,16 @@ + +import mysql from 'mysql2/promise'; + +// 데이터베이스 연결 설정 함수 +export const createDatabaseConnection = (config) => { + return mysql.createConnection({ + host: config.host, + user: config.user, + password: config.password, + database: config.database, + port: config.port, + waitForConnections: true, + connectionLimit: 10, + queueLimit: 0 + }); +}; \ No newline at end of file