[👷] 설정 작업

This commit is contained in:
김선규 2024-07-25 13:56:28 +09:00
parent 826f11719a
commit 3d3f6f2779
2 changed files with 61 additions and 0 deletions

45
apps/push.js Normal file
View File

@ -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}` });
});
}

16
db/database.js Normal file
View File

@ -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
});
};