Showing
3 changed files
with
59 additions
and
5 deletions
... | @@ -10,6 +10,7 @@ | ... | @@ -10,6 +10,7 @@ |
10 | "license": "ISC", | 10 | "license": "ISC", |
11 | "dependencies": { | 11 | "dependencies": { |
12 | "dotenv": "^10.0.0", | 12 | "dotenv": "^10.0.0", |
13 | + "ejs": "^3.1.6", | ||
13 | "express": "^4.17.1", | 14 | "express": "^4.17.1", |
14 | "mysql": "^2.18.1", | 15 | "mysql": "^2.18.1", |
15 | "path": "^0.12.7", | 16 | "path": "^0.12.7", | ... | ... |
... | @@ -5,9 +5,10 @@ const HTTPS = require("https"); | ... | @@ -5,9 +5,10 @@ const HTTPS = require("https"); |
5 | const mysql = require('mysql'); | 5 | const mysql = require('mysql'); |
6 | 6 | ||
7 | var address; | 7 | var address; |
8 | +var json_data = []; | ||
8 | 9 | ||
9 | const app = express(); | 10 | const app = express(); |
10 | -const domain = "2020105635.oss2021.tk"; | 11 | +const domain = "2020105619.oss2021.tk"; |
11 | const sslport = 8080; | 12 | const sslport = 8080; |
12 | 13 | ||
13 | const dotenv = require('dotenv').config(); //dotenv를 사용하기 위해서 dotenv 라이브러리를 불러온 뒤, config() 메소드를 호출 | 14 | const dotenv = require('dotenv').config(); //dotenv를 사용하기 위해서 dotenv 라이브러리를 불러온 뒤, config() 메소드를 호출 |
... | @@ -21,19 +22,31 @@ mysqlConObj.open(db); //db 연결 | ... | @@ -21,19 +22,31 @@ mysqlConObj.open(db); //db 연결 |
21 | 22 | ||
22 | db.query('SELECT * FROM csvdata.csvdata', function (error, results, fields) { | 23 | db.query('SELECT * FROM csvdata.csvdata', function (error, results, fields) { |
23 | if (error) { | 24 | if (error) { |
24 | - throw(error); | 25 | + throw (error); |
25 | } | 26 | } |
26 | - console.log(results.length); | ||
27 | }); | 27 | }); |
28 | 28 | ||
29 | app.get("/", function (req, res) { | 29 | app.get("/", function (req, res) { |
30 | res.sendFile(path.join(__dirname + "/main.html")); | 30 | res.sendFile(path.join(__dirname + "/main.html")); |
31 | }); | 31 | }); |
32 | 32 | ||
33 | +app.set("views", __dirname + "/views"); | ||
34 | +app.set("view engine", "ejs"); | ||
35 | + | ||
33 | app.get("/geolocation", function (req, res) { | 36 | app.get("/geolocation", function (req, res) { |
34 | address = req.query.address; | 37 | address = req.query.address; |
35 | - console.log(address); | 38 | + db.query('SELECT * FROM csvdata.csvdata', function (error, results, fields) { |
36 | - res.sendFile(path.join(__dirname + "/kakao/kakaomap.html")); | 39 | + if (error) { |
40 | + throw (error); | ||
41 | + } | ||
42 | + for (var i = 0; i < results.length; i++) { | ||
43 | + if (results[i].city_country == address) { | ||
44 | + json_data.push(results[i]); | ||
45 | + } | ||
46 | + } | ||
47 | + }); | ||
48 | + res.render('kakaomap', { 'data': json_data }) | ||
49 | + // res.sendFile(path.join(__dirname + "/kakao/kakaomap.html"), { json_data: json_data }); | ||
37 | }); | 50 | }); |
38 | 51 | ||
39 | try { | 52 | try { | ... | ... |
views/kakaomap.ejs
0 → 100644
1 | +<!DOCTYPE html> | ||
2 | +<html lang="en"> | ||
3 | + | ||
4 | +<head> | ||
5 | + <meta charset="UTR-8" /> | ||
6 | + <meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
7 | + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
8 | + <title>HomePurchaseAgePrediction</title> | ||
9 | + <link rel="stylesheet" href="css/style2.css" /> | ||
10 | + <link rel="preconnect" href="https://fonts.gstatic.com" /> | ||
11 | + <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@300;500;700;900&display=swap" | ||
12 | + rel="stylesheet" /> | ||
13 | +</head> | ||
14 | + | ||
15 | +<body> | ||
16 | + <nav> | ||
17 | + <p>js data : <%=data[0].add_adress%> | ||
18 | + </p> | ||
19 | + <h1 onClick="location.href='/'">Home Purchase Age Prediction</h1> | ||
20 | + </nav> | ||
21 | + <main> | ||
22 | + <div id="info"></div> | ||
23 | + <div id="home_info"> | ||
24 | + <div id="map"></div> | ||
25 | + <ul id="house_list"> | ||
26 | + <div>LIST</div> | ||
27 | + </ul> | ||
28 | + </div> | ||
29 | + </main> | ||
30 | + <script type="text/javascript" | ||
31 | + src="//dapi.kakao.com/v2/maps/sdk.js?appkey=17cbb7795b615d8f1f0595f972e26c0f&libraries=services,clusterer,drawing"></script> | ||
32 | + <script type="text/javascript" src="../js/next_page.js"></script> | ||
33 | + <% if(data){ %> | ||
34 | + <% for(let i=0;i < data.length;i++) { %> | ||
35 | + NAME : <%= data[i].add_adress %>, AGE : <%= data[i].amount %><br> | ||
36 | + <% } %> | ||
37 | + <% } %> | ||
38 | +</body> | ||
39 | + | ||
40 | +</html> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment