Showing
5 changed files
with
65 additions
and
13 deletions
... | @@ -8,7 +8,7 @@ const Mongoose = require('mongoose'); | ... | @@ -8,7 +8,7 @@ const Mongoose = require('mongoose'); |
8 | const api = require('./src/api'); | 8 | const api = require('./src/api'); |
9 | const MqttServer = require('./src/util/MqttServer'); | 9 | const MqttServer = require('./src/util/MqttServer'); |
10 | const BatchSystem = require('./src/util/Batch'); | 10 | const BatchSystem = require('./src/util/Batch'); |
11 | -const FCM = require('./src/util/FCM'); | 11 | +// const FCM = require('./src/util/FCM'); |
12 | 12 | ||
13 | require('dotenv').config(); | 13 | require('dotenv').config(); |
14 | // eslint-disable-next-line no-undef | 14 | // eslint-disable-next-line no-undef |
... | @@ -38,7 +38,7 @@ app.use(router.routes()).use(router.allowedMethods()); | ... | @@ -38,7 +38,7 @@ app.use(router.routes()).use(router.allowedMethods()); |
38 | app.listen(SERVER_PORT, () => { | 38 | app.listen(SERVER_PORT, () => { |
39 | console.log('\x1b[1;36mPORT : ', SERVER_PORT, 'is connected\x1b[0m'); | 39 | console.log('\x1b[1;36mPORT : ', SERVER_PORT, 'is connected\x1b[0m'); |
40 | MqttServer.on(); | 40 | MqttServer.on(); |
41 | - FCM.initializeFCM(); | 41 | + // FCM.initializeFCM(); |
42 | BatchSystem.removeQrCode(); | 42 | BatchSystem.removeQrCode(); |
43 | BatchSystem.pushNotifyByDosage(); | 43 | BatchSystem.pushNotifyByDosage(); |
44 | }); | 44 | }); |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -7,6 +7,7 @@ const hub = require('./hub'); | ... | @@ -7,6 +7,7 @@ const hub = require('./hub'); |
7 | const medicine = require('./medicine'); | 7 | const medicine = require('./medicine'); |
8 | const doctor = require('./doctor'); | 8 | const doctor = require('./doctor'); |
9 | const manage = require('./manage'); | 9 | const manage = require('./manage'); |
10 | +const test = require('./test'); | ||
10 | 11 | ||
11 | const api = new Router(); | 12 | const api = new Router(); |
12 | 13 | ||
... | @@ -17,5 +18,6 @@ api.use('/hub', hub.routes()); | ... | @@ -17,5 +18,6 @@ api.use('/hub', hub.routes()); |
17 | api.use('/medicine', medicine.routes()); | 18 | api.use('/medicine', medicine.routes()); |
18 | api.use('/doctor', doctor.routes()); | 19 | api.use('/doctor', doctor.routes()); |
19 | api.use('/manage', manage.routes()); | 20 | api.use('/manage', manage.routes()); |
21 | +api.use('/test', test.routes()); | ||
20 | 22 | ||
21 | module.exports = api; | 23 | module.exports = api; |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
server/src/api/test/index.js
0 → 100644
server/src/api/test/test.ctrl.js
0 → 100644
1 | +//테스트용 api service | ||
2 | +const { sendPushMessage } = require('../../util/FCM'); | ||
3 | + | ||
4 | + | ||
5 | +exports.sendFcmMessage = async ctx => { | ||
6 | + const { deviceToken, title, body } = ctx.request.body; | ||
7 | + | ||
8 | + try { | ||
9 | + await sendPushMessage(ctx.request.body); | ||
10 | + } catch(e) { | ||
11 | + console.log('Error at FCM Sending : ', e); | ||
12 | + } | ||
13 | +}; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | -const fcm = require('firebase-admin'); | 1 | +// const fcm = require('firebase-admin'); |
2 | +const axios = require('axios'); | ||
2 | 3 | ||
3 | - | 4 | +// exports.initializeFCM = () => { |
4 | -exports.initializeFCM = () => { | 5 | +// fcm.initializeApp({ |
5 | - fcm.initializeApp({ | 6 | +// credential: fcm.credential.applicationDefault(), |
6 | - credential : fcm.credential.applicationDefault(), | 7 | +// }); |
7 | - }); | 8 | +// }; |
8 | -}; | ||
9 | 9 | ||
10 | exports.sendPushMessage = async ({ deviceToken, title, body }) => { | 10 | exports.sendPushMessage = async ({ deviceToken, title, body }) => { |
11 | - const notifyMessage = { | 11 | + // const notifyMessage = { |
12 | + // notification : { | ||
13 | + // title, | ||
14 | + // body, | ||
15 | + // }, | ||
16 | + // token : deviceToken, | ||
17 | + // }; | ||
18 | + // fcm.messaging().send(notifyMessage).then(res => { | ||
19 | + // console.log(res); | ||
20 | + // }).catch(e => { | ||
21 | + // console.log(e); | ||
22 | + // }); | ||
23 | + | ||
24 | + const message = { | ||
25 | + to : deviceToken, | ||
12 | notification : { | 26 | notification : { |
13 | title, | 27 | title, |
14 | body, | 28 | body, |
29 | + priority : 'high', | ||
15 | }, | 30 | }, |
16 | - token : deviceToken, | 31 | + data : null, |
17 | - }; | 32 | + } |
18 | - fcm.messaging().send(notifyMessage); | 33 | + |
34 | + const url = 'https://fcm.googleapis.com/fcm/send'; | ||
35 | + const result = await axios.post(url, message, { | ||
36 | + headers : { | ||
37 | + 'Content-Type' : 'application/json', | ||
38 | + // eslint-disable-next-line no-undef | ||
39 | + 'Authorization' : `key=${process.env.FCM_KEY}`, | ||
40 | + }, | ||
41 | + }); | ||
42 | + | ||
43 | + console.log(result.data); | ||
19 | }; | 44 | }; |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment