Toggle navigation
Toggle navigation
This project
Loading...
Sign in
고혜연
/
DessertChatbot
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
고혜연
2021-06-10 11:30:26 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
2ac927a780f631d2994d6b17f09b72131875f629
2ac927a7
1 parent
aedfd523
Configure webhook
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
74 additions
and
13 deletions
https/app.js
https/constants.js
https/index.js
package.json
https/app.js
View file @
2ac927a
const
express
=
require
(
'express'
);
const
axios
=
require
(
'axios'
).
default
;
const
FormData
=
require
(
'form-data'
);
const
constants
=
require
(
'./constants'
);
const
app
=
express
();
app
.
use
(
express
.
json
());
app
.
get
(
'/'
,
(
req
,
res
)
=>
{
res
.
send
(
'Hello world!'
);
});
app
.
get
(
'/notify'
,
(
req
,
res
)
=>
{
const
url
=
'https://notify-api.line.me/api/notify'
const
form
=
new
FormData
();
form
.
append
(
'message'
,
'Line Notify Testing...'
);
form
.
append
(
'stickerPackageId'
,
1
);
form
.
append
(
'stickerId'
,
1
);
axios
.
post
(
url
,
form
,
{
headers
:
form
.
getHeaders
({
authorization
:
`Bearer
${
constants
.
LINE
.
TOKEN
}
`
})})
.
then
(
notifyResponse
=>
{
console
.
log
(
notifyResponse
);
res
.
status
(
200
);
res
.
send
(
'Request Success'
);
}).
catch
(
err
=>
{
console
.
log
(
err
);
res
.
send
(
'Request Error'
);
});
})
app
.
post
(
'/webhook'
,
(
req
,
res
)
=>
{
const
{
body
}
=
req
;
const
eventObj
=
body
.
events
[
0
];
const
{
source
,
message
,
replyToken
}
=
eventObj
;
// request log
console
.
log
(
'======================'
,
new
Date
()
,
'======================'
);
console
.
log
(
'[request]'
,
body
);
console
.
log
(
'[request source] '
,
source
);
console
.
log
(
'[request message]'
,
message
);
const
url
=
'https://notify-api.line.me/api/notify'
axios
.
post
(
url
,
{
replyToken
,
messages
:
[
{
type
:
'text'
,
text
:
'Hello!'
,
},
{
type
:
'text'
,
text
:
'May I Help U?'
,
},
],
},
{
headers
:
`Bearer
${
constants
.
LINE
.
TOKEN
}
`
,
}).
then
(
notifyResponse
=>
{
res
.
status
(
200
);
res
.
send
(
'Success'
);
}).
catch
(
err
=>
{
res
.
send
(
'Failed'
);
});
});
module
.
exports
=
app
;
\ No newline at end of file
...
...
https/constants.js
View file @
2ac927a
...
...
@@ -13,9 +13,9 @@ module.exports = {
CONFIG
:
{
PORT
:
443
,
HTTPS_OPTIONS
:
{
ca
:
fs
.
readFileSync
(
`/etc/letsencrypt/live/
${
domain
}
/fullchain.pem`
),
key
:
fs
.
readFileSync
(
path
.
resolve
(
process
.
cwd
(),
`/etc/letsencrypt/live/
${
domain
}
/privkey.pem`
),
'utf8'
).
toString
(),
cert
:
fs
.
readFileSync
(
path
.
resolve
(
process
.
cwd
(),
`/etc/letsencrypt/live/
${
domain
}
/cert.pem`
),
'utf8'
).
toString
(),
//
ca: fs.readFileSync(`/etc/letsencrypt/live/${domain}/fullchain.pem`),
//
key: fs.readFileSync(path.resolve(process.cwd(), `/etc/letsencrypt/live/${domain}/privkey.pem`), 'utf8').toString(),
//
cert: fs.readFileSync(path.resolve(process.cwd(), `/etc/letsencrypt/live/${domain}/cert.pem`), 'utf8').toString(),
}
}
};
\ No newline at end of file
...
...
https/index.js
View file @
2ac927a
...
...
@@ -3,12 +3,14 @@ const https = require('https');
const
app
=
require
(
'./app'
);
const
constants
=
require
(
'./constants'
);
try
{
const
options
=
constants
.
CONFIG
.
HTTPS_OPTIONS
;
https
.
createServer
(
options
,
app
).
listen
(
constants
.
CONFIG
.
PORT
,
()
=>
{
console
.
log
(
`[SYSTEM] HTTPS server is running on port
${
constants
.
CONFIG
.
PORT
}
`
);
})
}
catch
(
err
)
{
console
.
log
(
'[SYSTEM] Cannot start HTTPS server.'
);
console
.
log
(
err
);
}
\ No newline at end of file
// try {
// const options = constants.CONFIG.HTTPS_OPTIONS;
// https.createServer(options, app).listen(constants.CONFIG.PORT, () => {
// console.log(`[SYSTEM] HTTPS server is running on port ${constants.CONFIG.PORT}`);
// })
// } catch (err) {
// console.log('[SYSTEM] Cannot start HTTPS server.');
// console.log(err);
// }
app
.
listen
(
3000
);
\ No newline at end of file
...
...
package.json
View file @
2ac927a
...
...
@@ -22,7 +22,9 @@
"author"
:
"윤성아"
,
"license"
:
"MIT"
,
"dependencies"
:
{
"express"
:
"^4.17.1"
"axios"
:
"^0.21.1"
,
"express"
:
"^4.17.1"
,
"form-data"
:
"^4.0.0"
},
"devDependencies"
:{
"nodemon"
:
"^2.0.7"
...
...
Please
register
or
login
to post a comment