권주희

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
var createError = require("http-errors");
var express = require("express");
var cors = require("cors");
var path = require("path");
var cookieParser = require("cookie-parser");
var logger = require("morgan");
......@@ -9,6 +10,7 @@ var usersRouter = require("./routes/users");
var airConditionRouter = require("./routes/airCondition");
var app = express();
app.use(cors());
// view engine setup
app.set("views", path.join(__dirname, "views"));
......
......@@ -4,16 +4,16 @@
* Module dependencies.
*/
var app = require('../app');
var debug = require('debug')('backend:server');
var http = require('http');
var app = require("../app");
var debug = require("debug")("backend:server");
var http = require("http");
/**
* Get port from environment and store in Express.
*/
var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);
var port = normalizePort(process.env.PORT || "3001");
app.set("port", port);
/**
* Create HTTP server.
......@@ -26,8 +26,8 @@ var server = http.createServer(app);
*/
server.listen(port);
server.on('error', onError);
server.on('listening', onListening);
server.on("error", onError);
server.on("listening", onListening);
/**
* Normalize a port into a number, string, or false.
......@@ -54,22 +54,20 @@ function normalizePort(val) {
*/
function onError(error) {
if (error.syscall !== 'listen') {
if (error.syscall !== "listen") {
throw error;
}
var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;
var bind = typeof port === "string" ? "Pipe " + port : "Port " + port;
// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
case "EACCES":
console.error(bind + " requires elevated privileges");
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
case "EADDRINUSE":
console.error(bind + " is already in use");
process.exit(1);
break;
default:
......@@ -83,8 +81,6 @@ function onError(error) {
function onListening() {
var addr = server.address();
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
var bind = typeof addr === "string" ? "pipe " + addr : "port " + addr.port;
debug("Listening on " + bind);
}
......
......@@ -228,6 +228,15 @@
"resolved": "https://registry.npmjs.org/core-js/-/core-js-2.6.11.tgz",
"integrity": "sha512-5wjnpaT/3dV+XB4borEsnAYQchn00XSgTAWKDkEqv+K8KevjbzmofK6hfJ9TZIlpj2N0xQpazy7PiRQiWHqzWg=="
},
"cors": {
"version": "2.8.5",
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz",
"integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==",
"requires": {
"object-assign": "^4",
"vary": "^1"
}
},
"debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
......
......@@ -8,6 +8,7 @@
"dependencies": {
"axios": "^0.19.2",
"cookie-parser": "~1.4.3",
"cors": "^2.8.5",
"debug": "~2.6.9",
"express": "~4.16.0",
"http-errors": "~1.6.2",
......
......@@ -7,7 +7,7 @@ const googleMapKey = require("./secrets.json").googleAPIKey;
axios.create({
// TODO : 웹을 AWS에 올릴때, 해당 baseURL이 달라져야할 수 있음
baseURL: "http://localhost:3000",
baseURL: "http://localhost:3001",
responseType: "json",
});
......
import axios from "axios";
export default axios.create({
baseURL: "http://localhost:3000",
baseURL: "http://localhost:3001",
responseType: "json",
});
......
......@@ -6,7 +6,6 @@ import "./home.css";
import { Map, Marker, MarkerClusterer, Polyline } from "react-kakao-maps";
import "bootstrap/dist/css/bootstrap.min.css";
import API from "./API";
/* global kakao */
export default class Home extends Component {
......@@ -255,6 +254,25 @@ export default class Home extends Component {
let position = marker.getPosition();
console.log(marker.getPosition());
console.log(position["Ga"]);
API.get("/airCondition", {
params: {
latitude: position["Ha"],
longitude: position["Ga"],
},
})
.then((response) => {
console.log("Success");
console.log(response.data);
this.setState({
curAirCondition: response.data,
});
})
.catch(function (error) {
console.log(error);
})
.finally(function () {
// always executed
});
};
let setDepart = document.createElement("Button");
setDepart.innerHTML = "출발지로 설정하기";
......