Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2021-1-capstone-design1
/
RIT_Project1
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
1
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
박권수
2021-10-10 21:50:43 +0900
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
65634e1e40931bb287f220ccc529f41669fdc94f
65634e1e
2 parents
fddba9b0
dafee180
Merge branch 'server' into web
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
65 additions
and
13 deletions
server/index.js
server/src/api/index.js
server/src/api/test/index.js
server/src/api/test/test.ctrl.js
server/src/util/FCM.js
server/index.js
View file @
65634e1
...
...
@@ -8,7 +8,7 @@ const Mongoose = require('mongoose');
const
api
=
require
(
'./src/api'
);
const
MqttServer
=
require
(
'./src/util/MqttServer'
);
const
BatchSystem
=
require
(
'./src/util/Batch'
);
const
FCM
=
require
(
'./src/util/FCM'
);
//
const FCM = require('./src/util/FCM');
require
(
'dotenv'
).
config
();
// eslint-disable-next-line no-undef
...
...
@@ -38,7 +38,7 @@ app.use(router.routes()).use(router.allowedMethods());
app
.
listen
(
SERVER_PORT
,
()
=>
{
console
.
log
(
'\x1b[1;36mPORT : '
,
SERVER_PORT
,
'is connected\x1b[0m'
);
MqttServer
.
on
();
FCM
.
initializeFCM
();
//
FCM.initializeFCM();
BatchSystem
.
removeQrCode
();
BatchSystem
.
pushNotifyByDosage
();
});
\ No newline at end of file
...
...
server/src/api/index.js
View file @
65634e1
...
...
@@ -7,6 +7,7 @@ const hub = require('./hub');
const
medicine
=
require
(
'./medicine'
);
const
doctor
=
require
(
'./doctor'
);
const
manage
=
require
(
'./manage'
);
const
test
=
require
(
'./test'
);
const
api
=
new
Router
();
...
...
@@ -17,5 +18,6 @@ api.use('/hub', hub.routes());
api
.
use
(
'/medicine'
,
medicine
.
routes
());
api
.
use
(
'/doctor'
,
doctor
.
routes
());
api
.
use
(
'/manage'
,
manage
.
routes
());
api
.
use
(
'/test'
,
test
.
routes
());
module
.
exports
=
api
;
\ No newline at end of file
...
...
server/src/api/test/index.js
0 → 100644
View file @
65634e1
//test용 api입니다.
const
Router
=
require
(
'koa-router'
);
const
testCtrl
=
require
(
'./test.ctrl'
);
const
test
=
new
Router
();
//푸쉬메시지 테스트
test
.
post
(
'/fcm'
,
testCtrl
.
sendFcmMessage
);
module
.
exports
=
test
;
server/src/api/test/test.ctrl.js
0 → 100644
View file @
65634e1
//테스트용 api service
const
{
sendPushMessage
}
=
require
(
'../../util/FCM'
);
exports
.
sendFcmMessage
=
async
ctx
=>
{
const
{
deviceToken
,
title
,
body
}
=
ctx
.
request
.
body
;
try
{
await
sendPushMessage
(
ctx
.
request
.
body
);
}
catch
(
e
)
{
console
.
log
(
'Error at FCM Sending : '
,
e
);
}
};
\ No newline at end of file
server/src/util/FCM.js
View file @
65634e1
const
fcm
=
require
(
'firebase-admin'
);
// const fcm = require('firebase-admin');
const
axios
=
require
(
'axios'
);
exports
.
initializeFCM
=
()
=>
{
fcm
.
initializeApp
({
credential
:
fcm
.
credential
.
applicationDefault
(),
});
};
// exports.initializeFCM = () => {
// fcm.initializeApp({
// credential: fcm.credential.applicationDefault(),
// });
// };
exports
.
sendPushMessage
=
async
({
deviceToken
,
title
,
body
})
=>
{
const
notifyMessage
=
{
// const notifyMessage = {
// notification : {
// title,
// body,
// },
// token : deviceToken,
// };
// fcm.messaging().send(notifyMessage).then(res => {
// console.log(res);
// }).catch(e => {
// console.log(e);
// });
const
message
=
{
to
:
deviceToken
,
notification
:
{
title
,
body
,
priority
:
'high'
,
},
token
:
deviceToken
,
};
fcm
.
messaging
().
send
(
notifyMessage
);
data
:
null
,
}
const
url
=
'https://fcm.googleapis.com/fcm/send'
;
const
result
=
await
axios
.
post
(
url
,
message
,
{
headers
:
{
'Content-Type'
:
'application/json'
,
// eslint-disable-next-line no-undef
'Authorization'
:
`key=
${
process
.
env
.
FCM_KEY
}
`
,
},
});
console
.
log
(
result
.
data
);
};
\ No newline at end of file
...
...
Please
register
or
login
to post a comment