Toggle navigation
Toggle navigation
This project
Loading...
Sign in
오지민
/
HomePurchaseAgePrediction
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
Ojimin
2021-06-09 18:24:25 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
113a7ac64b97d1ee1e21fba6775ef237d18cbaf5
113a7ac6
1 parent
d64e9f14
Update mysql module and Create rest api
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
52 additions
and
23 deletions
.env
.gitignore
api.js
config/mysql.js
package.json
server.js
.env
0 → 100644
View file @
113a7ac
host=dataserver.chilwi8knzrl.us-east-1.rds.amazonaws.com
user=admin
password=apple0606!
port=3306
database=csvdata
.gitignore
View file @
113a7ac
...
...
@@ -2,5 +2,3 @@ node_modules/
package-lock.json
#database
database.json
\ No newline at end of file
...
...
api.js
0 → 100644
View file @
113a7ac
const
express
=
require
(
'express'
);
const
mysql
=
require
(
'mysql'
);
const
app
=
express
();
const
dotenv
=
require
(
'dotenv'
).
config
();
//dotenv를 사용하기 위해서 dotenv 라이브러리를 불러온 뒤, config() 메소드를 호출
const
mysqlConObj
=
require
(
'./config/mysql'
);
//config의 mysql파일을 가져와 mysqlConnection 객체 사용
const
db
=
mysqlConObj
.
init
();
mysqlConObj
.
open
(
db
);
//db 연결
config/mysql.js
0 → 100644
View file @
113a7ac
const
mysql
=
require
(
'mysql'
);
// mysql 드라이버 불러오기
const
mysqlConnection
=
{
init
:
function
()
{
//DB와 연결하는 객체 생성
return
mysql
.
createConnection
({
host
:
process
.
env
.
host
,
user
:
process
.
env
.
user
,
password
:
process
.
env
.
password
,
port
:
process
.
env
.
port
,
database
:
process
.
env
.
database
});
},
open
:
function
(
con
)
{
//생성된 객체를 DB와 연결
con
.
connect
(
err
=>
{
if
(
err
){
console
.
log
(
"MySQL 연결 실패 : "
,
err
);
}
else
{
console
.
log
(
"MySQL 연결 성공"
);
}
});
},
close
:
function
(
con
){
//DB와 연결을 종료
con
.
end
(
err
=>
{
if
(
err
){
console
.
log
(
"MySQL 종료 실패 : "
,
err
);
}
else
{
console
.
log
(
"MySQL Terminated..."
);
}
})
}
}
module
.
exports
=
mysqlConnection
;
//생성한 mysqlConnection 객체를 모듈화하여 외부 파일에서 불러와 사용할 수 있도록 export함
\ No newline at end of file
package.json
View file @
113a7ac
...
...
@@ -9,6 +9,7 @@
"author"
:
""
,
"license"
:
"ISC"
,
"dependencies"
:
{
"dotenv"
:
"^10.0.0"
,
"express"
:
"^4.17.1"
,
"mysql"
:
"^2.18.1"
,
"path"
:
"^0.12.7"
,
...
...
server.js
View file @
113a7ac
...
...
@@ -4,38 +4,18 @@ const path = require("path");
const
HTTPS
=
require
(
"https"
);
const
app
=
express
();
const
domain
=
"20201056
19
.oss2021.tk"
;
const
domain
=
"20201056
35
.oss2021.tk"
;
const
sslport
=
8080
;
const
data
=
fs
.
readFileSync
(
'database.json'
);
const
conf
=
JSON
.
parse
(
data
);
const
mysql
=
require
(
'mysql'
);
app
.
use
(
express
.
static
(
path
.
join
(
__dirname
,
"kakao"
)));
app
.
use
(
express
.
static
(
path
.
join
(
__dirname
,
"public"
)));
const
connection
=
mysql
.
createConnection
({
host
:
conf
.
host
,
user
:
conf
.
user
,
password
:
conf
.
password
,
port
:
conf
.
port
,
database
:
conf
.
database
});
connection
.
connect
();
app
.
get
(
"/"
,
function
(
req
,
res
)
{
res
.
sendFile
(
path
.
join
(
__dirname
+
"/main.html"
));
});
app
.
get
(
"/geolocation"
,
function
(
req
,
res
)
{
res
.
sendFile
(
path
.
join
(
__dirname
+
"/kakao/kakaomap.html"
));
connection
.
query
(
'SELECT * FROM csvdata.csvdata'
,
function
(
error
,
results
,
fields
)
{
if
(
error
)
{
throw
(
error
);
}
res
.
send
(
results
);
});
});
try
{
...
...
Please
register
or
login
to post a comment