Merge branch 'feature/getCurAirInfo' into 'develop'
Feature/get cur air info - get Current Location's Air Information Using API - get Current Location's Air Information Using API - install axios - allow the CORS error to Backend app - display the result of current air information - display the result of current air information - add icon See merge request !4
Showing
17 changed files
with
138 additions
and
20 deletions
1 | var createError = require("http-errors"); | 1 | var createError = require("http-errors"); |
2 | var express = require("express"); | 2 | var express = require("express"); |
3 | +var cors = require("cors"); | ||
3 | var path = require("path"); | 4 | var path = require("path"); |
4 | var cookieParser = require("cookie-parser"); | 5 | var cookieParser = require("cookie-parser"); |
5 | var logger = require("morgan"); | 6 | var logger = require("morgan"); |
... | @@ -9,6 +10,7 @@ var usersRouter = require("./routes/users"); | ... | @@ -9,6 +10,7 @@ var usersRouter = require("./routes/users"); |
9 | var airConditionRouter = require("./routes/airCondition"); | 10 | var airConditionRouter = require("./routes/airCondition"); |
10 | 11 | ||
11 | var app = express(); | 12 | var app = express(); |
13 | +app.use(cors()); | ||
12 | 14 | ||
13 | // view engine setup | 15 | // view engine setup |
14 | app.set("views", path.join(__dirname, "views")); | 16 | app.set("views", path.join(__dirname, "views")); | ... | ... |
... | @@ -4,16 +4,16 @@ | ... | @@ -4,16 +4,16 @@ |
4 | * Module dependencies. | 4 | * Module dependencies. |
5 | */ | 5 | */ |
6 | 6 | ||
7 | -var app = require('../app'); | 7 | +var app = require("../app"); |
8 | -var debug = require('debug')('backend:server'); | 8 | +var debug = require("debug")("backend:server"); |
9 | -var http = require('http'); | 9 | +var http = require("http"); |
10 | 10 | ||
11 | /** | 11 | /** |
12 | * Get port from environment and store in Express. | 12 | * Get port from environment and store in Express. |
13 | */ | 13 | */ |
14 | 14 | ||
15 | -var port = normalizePort(process.env.PORT || '3000'); | 15 | +var port = normalizePort(process.env.PORT || "3001"); |
16 | -app.set('port', port); | 16 | +app.set("port", port); |
17 | 17 | ||
18 | /** | 18 | /** |
19 | * Create HTTP server. | 19 | * Create HTTP server. |
... | @@ -26,8 +26,8 @@ var server = http.createServer(app); | ... | @@ -26,8 +26,8 @@ var server = http.createServer(app); |
26 | */ | 26 | */ |
27 | 27 | ||
28 | server.listen(port); | 28 | server.listen(port); |
29 | -server.on('error', onError); | 29 | +server.on("error", onError); |
30 | -server.on('listening', onListening); | 30 | +server.on("listening", onListening); |
31 | 31 | ||
32 | /** | 32 | /** |
33 | * Normalize a port into a number, string, or false. | 33 | * Normalize a port into a number, string, or false. |
... | @@ -54,22 +54,20 @@ function normalizePort(val) { | ... | @@ -54,22 +54,20 @@ function normalizePort(val) { |
54 | */ | 54 | */ |
55 | 55 | ||
56 | function onError(error) { | 56 | function onError(error) { |
57 | - if (error.syscall !== 'listen') { | 57 | + if (error.syscall !== "listen") { |
58 | throw error; | 58 | throw error; |
59 | } | 59 | } |
60 | 60 | ||
61 | - var bind = typeof port === 'string' | 61 | + var bind = typeof port === "string" ? "Pipe " + port : "Port " + port; |
62 | - ? 'Pipe ' + port | ||
63 | - : 'Port ' + port; | ||
64 | 62 | ||
65 | // handle specific listen errors with friendly messages | 63 | // handle specific listen errors with friendly messages |
66 | switch (error.code) { | 64 | switch (error.code) { |
67 | - case 'EACCES': | 65 | + case "EACCES": |
68 | - console.error(bind + ' requires elevated privileges'); | 66 | + console.error(bind + " requires elevated privileges"); |
69 | process.exit(1); | 67 | process.exit(1); |
70 | break; | 68 | break; |
71 | - case 'EADDRINUSE': | 69 | + case "EADDRINUSE": |
72 | - console.error(bind + ' is already in use'); | 70 | + console.error(bind + " is already in use"); |
73 | process.exit(1); | 71 | process.exit(1); |
74 | break; | 72 | break; |
75 | default: | 73 | default: |
... | @@ -83,8 +81,6 @@ function onError(error) { | ... | @@ -83,8 +81,6 @@ function onError(error) { |
83 | 81 | ||
84 | function onListening() { | 82 | function onListening() { |
85 | var addr = server.address(); | 83 | var addr = server.address(); |
86 | - var bind = typeof addr === 'string' | 84 | + var bind = typeof addr === "string" ? "pipe " + addr : "port " + addr.port; |
87 | - ? 'pipe ' + addr | 85 | + debug("Listening on " + bind); |
88 | - : 'port ' + addr.port; | ||
89 | - debug('Listening on ' + bind); | ||
90 | } | 86 | } | ... | ... |
... | @@ -228,6 +228,15 @@ | ... | @@ -228,6 +228,15 @@ |
228 | "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.6.11.tgz", | 228 | "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.6.11.tgz", |
229 | "integrity": "sha512-5wjnpaT/3dV+XB4borEsnAYQchn00XSgTAWKDkEqv+K8KevjbzmofK6hfJ9TZIlpj2N0xQpazy7PiRQiWHqzWg==" | 229 | "integrity": "sha512-5wjnpaT/3dV+XB4borEsnAYQchn00XSgTAWKDkEqv+K8KevjbzmofK6hfJ9TZIlpj2N0xQpazy7PiRQiWHqzWg==" |
230 | }, | 230 | }, |
231 | + "cors": { | ||
232 | + "version": "2.8.5", | ||
233 | + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", | ||
234 | + "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==", | ||
235 | + "requires": { | ||
236 | + "object-assign": "^4", | ||
237 | + "vary": "^1" | ||
238 | + } | ||
239 | + }, | ||
231 | "debug": { | 240 | "debug": { |
232 | "version": "2.6.9", | 241 | "version": "2.6.9", |
233 | "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", | 242 | "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", | ... | ... |
... | @@ -8,6 +8,7 @@ | ... | @@ -8,6 +8,7 @@ |
8 | "dependencies": { | 8 | "dependencies": { |
9 | "axios": "^0.19.2", | 9 | "axios": "^0.19.2", |
10 | "cookie-parser": "~1.4.3", | 10 | "cookie-parser": "~1.4.3", |
11 | + "cors": "^2.8.5", | ||
11 | "debug": "~2.6.9", | 12 | "debug": "~2.6.9", |
12 | "express": "~4.16.0", | 13 | "express": "~4.16.0", |
13 | "http-errors": "~1.6.2", | 14 | "http-errors": "~1.6.2", | ... | ... |
... | @@ -7,7 +7,7 @@ const googleMapKey = require("./secrets.json").googleAPIKey; | ... | @@ -7,7 +7,7 @@ const googleMapKey = require("./secrets.json").googleAPIKey; |
7 | 7 | ||
8 | axios.create({ | 8 | axios.create({ |
9 | // TODO : 웹을 AWS에 올릴때, 해당 baseURL이 달라져야할 수 있음 | 9 | // TODO : 웹을 AWS에 올릴때, 해당 baseURL이 달라져야할 수 있음 |
10 | - baseURL: "http://localhost:3000", | 10 | + baseURL: "http://localhost:3001", |
11 | responseType: "json", | 11 | responseType: "json", |
12 | }); | 12 | }); |
13 | 13 | ... | ... |
... | @@ -2636,6 +2636,37 @@ | ... | @@ -2636,6 +2636,37 @@ |
2636 | "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.9.1.tgz", | 2636 | "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.9.1.tgz", |
2637 | "integrity": "sha512-wMHVg2EOHaMRxbzgFJ9gtjOOCrI80OHLG14rxi28XwOW8ux6IiEbRCGGGqCtdAIg4FQCbW20k9RsT4y3gJlFug==" | 2637 | "integrity": "sha512-wMHVg2EOHaMRxbzgFJ9gtjOOCrI80OHLG14rxi28XwOW8ux6IiEbRCGGGqCtdAIg4FQCbW20k9RsT4y3gJlFug==" |
2638 | }, | 2638 | }, |
2639 | + "axios": { | ||
2640 | + "version": "0.19.2", | ||
2641 | + "resolved": "https://registry.npmjs.org/axios/-/axios-0.19.2.tgz", | ||
2642 | + "integrity": "sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==", | ||
2643 | + "requires": { | ||
2644 | + "follow-redirects": "1.5.10" | ||
2645 | + }, | ||
2646 | + "dependencies": { | ||
2647 | + "debug": { | ||
2648 | + "version": "3.1.0", | ||
2649 | + "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", | ||
2650 | + "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", | ||
2651 | + "requires": { | ||
2652 | + "ms": "2.0.0" | ||
2653 | + } | ||
2654 | + }, | ||
2655 | + "follow-redirects": { | ||
2656 | + "version": "1.5.10", | ||
2657 | + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz", | ||
2658 | + "integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==", | ||
2659 | + "requires": { | ||
2660 | + "debug": "=3.1.0" | ||
2661 | + } | ||
2662 | + }, | ||
2663 | + "ms": { | ||
2664 | + "version": "2.0.0", | ||
2665 | + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", | ||
2666 | + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" | ||
2667 | + } | ||
2668 | + } | ||
2669 | + }, | ||
2639 | "axobject-query": { | 2670 | "axobject-query": { |
2640 | "version": "2.1.2", | 2671 | "version": "2.1.2", |
2641 | "resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-2.1.2.tgz", | 2672 | "resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-2.1.2.tgz", | ... | ... |
... | @@ -6,6 +6,7 @@ | ... | @@ -6,6 +6,7 @@ |
6 | "@testing-library/jest-dom": "^4.2.4", | 6 | "@testing-library/jest-dom": "^4.2.4", |
7 | "@testing-library/react": "^9.3.2", | 7 | "@testing-library/react": "^9.3.2", |
8 | "@testing-library/user-event": "^7.1.2", | 8 | "@testing-library/user-event": "^7.1.2", |
9 | + "axios": "^0.19.2", | ||
9 | "bootstrap": "^3.4.1", | 10 | "bootstrap": "^3.4.1", |
10 | "daum-map-api": "^1.0.2", | 11 | "daum-map-api": "^1.0.2", |
11 | "react": "^16.13.1", | 12 | "react": "^16.13.1", | ... | ... |
frontend/src/API.js
0 → 100644
frontend/src/gradeIcon/angry.png
0 → 100644
27.5 KB
frontend/src/gradeIcon/cool.png
0 → 100644
23.4 KB
frontend/src/gradeIcon/devil.png
0 → 100644
29.4 KB
frontend/src/gradeIcon/finish.png
0 → 100644
30 KB
frontend/src/gradeIcon/loading.gif
0 → 100644
17.1 KB
frontend/src/gradeIcon/next.png
0 → 100644
5.67 KB
frontend/src/gradeIcon/smile.png
0 → 100644
27.5 KB
frontend/src/gradeIcon/start.png
0 → 100644
13.3 KB
... | @@ -5,6 +5,12 @@ import Button from "react-bootstrap/Button"; | ... | @@ -5,6 +5,12 @@ import Button from "react-bootstrap/Button"; |
5 | import "./home.css"; | 5 | import "./home.css"; |
6 | import { Map, Marker, MarkerClusterer, Polyline } from "react-kakao-maps"; | 6 | import { Map, Marker, MarkerClusterer, Polyline } from "react-kakao-maps"; |
7 | import "bootstrap/dist/css/bootstrap.min.css"; | 7 | import "bootstrap/dist/css/bootstrap.min.css"; |
8 | +import API from "./API"; | ||
9 | +import veryGood from "./gradeIcon/cool.png"; | ||
10 | +import good from "./gradeIcon/smile.png"; | ||
11 | +import bad from "./gradeIcon/angry.png"; | ||
12 | +import veryBad from "./gradeIcon/devil.png"; | ||
13 | +import next from "./gradeIcon/next.png"; | ||
8 | 14 | ||
9 | /* global kakao */ | 15 | /* global kakao */ |
10 | 16 | ||
... | @@ -21,6 +27,7 @@ export default class Home extends Component { | ... | @@ -21,6 +27,7 @@ export default class Home extends Component { |
21 | placeSearch: new kakao.maps.services.Places(), | 27 | placeSearch: new kakao.maps.services.Places(), |
22 | infoWindow: new kakao.maps.CustomOverlay({}), | 28 | infoWindow: new kakao.maps.CustomOverlay({}), |
23 | region: "은평구청", | 29 | region: "은평구청", |
30 | + curAirCondition: null, | ||
24 | 31 | ||
25 | // curAirCondition: null, | 32 | // curAirCondition: null, |
26 | // routeInformation: null, | 33 | // routeInformation: null, |
... | @@ -254,6 +261,25 @@ export default class Home extends Component { | ... | @@ -254,6 +261,25 @@ export default class Home extends Component { |
254 | let position = marker.getPosition(); | 261 | let position = marker.getPosition(); |
255 | console.log(marker.getPosition()); | 262 | console.log(marker.getPosition()); |
256 | console.log(position["Ga"]); | 263 | console.log(position["Ga"]); |
264 | + API.get("/airCondition", { | ||
265 | + params: { | ||
266 | + latitude: position["Ha"], | ||
267 | + longitude: position["Ga"], | ||
268 | + }, | ||
269 | + }) | ||
270 | + .then((response) => { | ||
271 | + console.log("Success"); | ||
272 | + console.log(response.data); | ||
273 | + this.setState({ | ||
274 | + curAirCondition: response.data, | ||
275 | + }); | ||
276 | + }) | ||
277 | + .catch(function (error) { | ||
278 | + console.log(error); | ||
279 | + }) | ||
280 | + .finally(function () { | ||
281 | + // always executed | ||
282 | + }); | ||
257 | }; | 283 | }; |
258 | let setDepart = document.createElement("Button"); | 284 | let setDepart = document.createElement("Button"); |
259 | setDepart.innerHTML = "출발지로 설정하기"; | 285 | setDepart.innerHTML = "출발지로 설정하기"; |
... | @@ -309,6 +335,52 @@ export default class Home extends Component { | ... | @@ -309,6 +335,52 @@ export default class Home extends Component { |
309 | 335 | ||
310 | render() { | 336 | render() { |
311 | let currentAirCondition = null; | 337 | let currentAirCondition = null; |
338 | + if (this.state.curAirCondition != null) { | ||
339 | + let pm10Image = null; | ||
340 | + let pm25Image = null; | ||
341 | + switch (this.state.curAirCondition.pm10Grade) { | ||
342 | + case "1": | ||
343 | + pm10Image = <img src={veryGood} width="50px" heigth="100px" />; | ||
344 | + break; | ||
345 | + case "2": | ||
346 | + pm10Image = <img src={good} width="50px" heigth="100px" />; | ||
347 | + break; | ||
348 | + case "3": | ||
349 | + pm10Image = <img src={bad} width="50px" heigth="100px" />; | ||
350 | + break; | ||
351 | + case "4": | ||
352 | + pm10Image = <img src={veryBad} width="50px" heigth="100px" />; | ||
353 | + break; | ||
354 | + default: | ||
355 | + pm10Image = null; | ||
356 | + } | ||
357 | + switch (this.state.curAirCondition.pm25Grade) { | ||
358 | + case "1": | ||
359 | + pm25Image = <img src={veryGood} width="50px" heigth="100px" />; | ||
360 | + break; | ||
361 | + case "2": | ||
362 | + pm25Image = <img src={good} width="50px" heigth="100px" />; | ||
363 | + break; | ||
364 | + case "3": | ||
365 | + pm25Image = <img src={bad} width="50px" heigth="100px" />; | ||
366 | + break; | ||
367 | + case "4": | ||
368 | + pm25Image = <img src={veryBad} width="50px" heigth="100px" />; | ||
369 | + break; | ||
370 | + default: | ||
371 | + pm25Image = null; | ||
372 | + } | ||
373 | + currentAirCondition = ( | ||
374 | + <h5> | ||
375 | + <br /> | ||
376 | + <br /> | ||
377 | + <br /> 미세먼지 등급 <br /> {pm10Image} <br /> | ||
378 | + 미세먼지 지수 : {this.state.curAirCondition.pm10Value} <br /> | ||
379 | + 초미세먼지 등급 <br /> {pm25Image} <br /> | ||
380 | + 초미세먼지 지수 : {this.state.curAirCondition.pm25Value} <br />{" "} | ||
381 | + </h5> | ||
382 | + ); | ||
383 | + } | ||
312 | let routeAirCondition = null; | 384 | let routeAirCondition = null; |
313 | 385 | ||
314 | return ( | 386 | return ( | ... | ... |
-
Please register or login to post a comment