Toggle navigation
Toggle navigation
This project
Loading...
Sign in
곽원석
/
OSS-Project
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
곽원석
2020-12-08 08:22:05 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
39af0e825f3357ef127bdef3230b85161e5b686f
39af0e82
1 parent
8753d789
update to development_branch
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
106 additions
and
23 deletions
app.js
package-lock.json
package.json
app.js
View file @
39af0e8
//웹 프레임 웤
var
express
=
require
(
'express'
);
var
app
=
express
();
// 요청 리소스 표현 모듈
var
request
=
require
(
'request'
);
// api의 데이터포맷이 xml이므로 json으로 파싱할 필요가 있음
var
convert
=
require
(
'xml-js'
);
const
bodyParser
=
require
(
'body-parser'
);
// 라인 메신져
const
TARGET_URL
=
'https://api.line.me/v2/bot/message/reply'
const
TOKEN
=
'EyomUcCS5ksQZGEvfMJX4JsOZ3C3qrdnU7dK11wHngy'
// 공공보건포털_API
var
request
=
require
(
'request'
);
// 파싱할 URL
var
url
=
'http://openapi.data.go.kr/openapi/service/rest/Covid19/getCovid19InfStateJson'
;
var
queryParams
=
'?'
+
encodeURIComponent
(
'ServiceKey'
)
+
'=서비스키'
;
/* Service Key*/
queryParams
+=
'&'
+
encodeURIComponent
(
'pageNo'
)
+
'='
+
encodeURIComponent
(
'1'
);
/* */
queryParams
+=
'&'
+
encodeURIComponent
(
'numOfRows'
)
+
'='
+
encodeURIComponent
(
'10'
);
/* */
queryParams
+=
'&'
+
encodeURIComponent
(
'startCreateDt'
)
+
'='
+
encodeURIComponent
(
'20200310'
);
/* */
queryParams
+=
'&'
+
encodeURIComponent
(
'endCreateDt'
)
+
'='
+
encodeURIComponent
(
'20200315'
);
/* */
request
({
const
TARGET_URL2
=
'http://openapi.data.go.kr/openapi/service/rest/Covid19/getCovid19InfStateJson'
;
const
SERVICE_KEY
=
'DMUPOq6b%2B%2F1gqfLEXQ6bnhgoTO73BfPprA6HVNcV%2F6vHMGG%2Bgiw%2BPDkPvX1eQ7b9uvl%2B42fxUPkU0W3Si907Lw%3D%3D'
// express 미들웨어 정의
var
app
=
express
();
// 기타 비동기식 오류처리에 쓰일 모듈들
const
fs
=
require
(
'fs'
);
const
path
=
require
(
'path'
);
const
HTTPS
=
require
(
'https'
);
const
domain
=
"www.oss-chatbot-kwak.tk"
const
sslport
=
23023
;
// 챗봇으로 입력
app
.
post
(
'/hook'
,
function
(
request
,
response
)
{
var
eventObj
=
request
.
body
.
events
[
0
];
var
source
=
eventObj
.
source
;
var
message
=
eventObj
.
message
;
// request log
console
.
log
(
'======================'
,
new
Date
()
,
'======================'
);
console
.
log
(
'[request]'
,
request
.
body
);
console
.
log
(
'[request source] '
,
eventObj
.
source
);
console
.
log
(
'[request message]'
,
eventObj
.
message
);
response
.
sendStatus
(
200
);
});
/* 요청변수
var queryParams = '?' + encodeURIComponent('ServiceKey') + '=DMUPOq6b%2B%2F1gqfLEXQ6bnhgoTO73BfPprA6HVNcV%2F6vHMGG%2Bgiw%2BPDkPvX1eQ7b9uvl%2B42fxUPkU0W3Si907Lw%3D%3D'; // Service Key
queryParams += '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent('1');
queryParams += '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent('10');
queryParams += '&' + encodeURIComponent('startCreateDt') + '=' + encodeURIComponent('20200310');
queryParams += '&' + encodeURIComponent('endCreateDt') + '=' + encodeURIComponent('20200315');
*/
// 공공보건포털에 요청
app
.
request
({
url
:
url
+
queryParams
,
method
:
'GET'
},
function
(
error
,
response
,
body
)
{
//console.log('Status', response.statusCode);
//console.log('Headers', JSON.stringify(response.headers));
//console.log('Reponse received', body);
});
\ No newline at end of file
console
.
log
(
'Status'
,
response
.
statusCode
);
console
.
log
(
'Headers'
,
JSON
.
stringify
(
response
.
headers
));
console
.
log
(
'Reponse received'
,
body
);
});
function
getResponeElement
({
});
// 오류처리
try
{
const
option
=
{
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
(),
};
HTTPS
.
createServer
(
option
,
app
).
listen
(
sslport
,
()
=>
{
console
.
log
(
`[HTTPS] Server is started on port
${
sslport
}
`
);
});
}
catch
(
error
)
{
console
.
log
(
'[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.'
);
console
.
log
(
error
);
}
...
...
package-lock.json
View file @
39af0e8
This diff is collapsed. Click to expand it.
package.json
View file @
39af0e8
...
...
@@ -4,13 +4,21 @@
"description"
:
""
,
"main"
:
"app.js"
,
"scripts"
:
{
"test"
:
"echo
\"
Error: no test specified
\"
&& exit 1"
,
"start"
:
"node server.js"
"test"
:
"echo
\"
Error: no test specified
\"
&& exit 1"
},
"author"
:
"KwakWonseok"
,
"license"
:
"MIT"
,
"dependencies"
:
{
"@line/bot-sdk"
:
"^6.4.0"
,
"express"
:
"^4.16.4"
"repository"
:
{
"type"
:
"git"
,
"url"
:
"http://khuhub.khu.ac.kr/2014104077/OSS-Project.git"
}
"author"
:
{
"name"
:
"KwakWonseok"
,
"email"
:
"rhkrdnjstjr1@khu.ac.kr"
,
"url"
:
"http://khuhub.khu.ac.kr/u/2014104077"
}
"license"
:
"MIT"
,
"dependencies"
:
{
"@line/bot-sdk"
:
"^6.4.0"
,
"express"
:
"^4.17.1"
,
"request"
:
"^2.88.2"
}
}
}
...
...
Please
register
or
login
to post a comment