Showing
9 changed files
with
54 additions
and
32 deletions
... | @@ -3,14 +3,17 @@ import {useEffect} from "react"; | ... | @@ -3,14 +3,17 @@ import {useEffect} from "react"; |
3 | import './App.css'; | 3 | import './App.css'; |
4 | 4 | ||
5 | function App() { | 5 | function App() { |
6 | + console.log("ang"); | ||
6 | const callApi = async () => { | 7 | const callApi = async () => { |
7 | - axios.get("/api").then((res) => console.log(res.data.test)); | 8 | + axios.get("/test").then((res) => console.log(res.data.test)); |
8 | }; | 9 | }; |
10 | + | ||
9 | useEffect(() => { | 11 | useEffect(() => { |
10 | callApi(); | 12 | callApi(); |
11 | - }, []); | 13 | + },); |
12 | 14 | ||
13 | - return <div>test</div>; | 15 | + return (<div>test</div>); |
14 | } | 16 | } |
15 | 17 | ||
18 | + | ||
16 | export default App; | 19 | export default App; |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -2,8 +2,10 @@ const proxy = require('http-proxy-middleware'); | ... | @@ -2,8 +2,10 @@ const proxy = require('http-proxy-middleware'); |
2 | 2 | ||
3 | module.exports = function (app) { | 3 | module.exports = function (app) { |
4 | app.use( | 4 | app.use( |
5 | - proxy.createProxyMiddleware('/api', { | 5 | + proxy.createProxyMiddleware('/', { |
6 | - target: 'http://localhost:5000/' | 6 | + target: 'http://localhost:5000/', |
7 | + changeOrigin : true | ||
7 | }) | 8 | }) |
9 | + | ||
8 | ); | 10 | ); |
9 | }; | 11 | }; |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
This diff is collapsed. Click to expand it.
... | @@ -5,8 +5,13 @@ | ... | @@ -5,8 +5,13 @@ |
5 | "start": "concurrently --kill-others-on-fail \"npm run server\" \"npm run client\"" | 5 | "start": "concurrently --kill-others-on-fail \"npm run server\" \"npm run client\"" |
6 | }, | 6 | }, |
7 | "dependencies": { | 7 | "dependencies": { |
8 | + "body-parser": "^1.19.0", | ||
8 | "concurrently": "^6.4.0", | 9 | "concurrently": "^6.4.0", |
10 | + "cors": "^2.8.5", | ||
9 | "express": "^4.17.1", | 11 | "express": "^4.17.1", |
10 | - "nodemon": "^2.0.15" | 12 | + "moment": "^2.29.1", |
13 | + "moment-timezone": "^0.5.34", | ||
14 | + "nodemon": "^2.0.15", | ||
15 | + "request": "^2.88.2" | ||
11 | } | 16 | } |
12 | } | 17 | } | ... | ... |
1 | +const express = require('express'); | ||
2 | +const router = express.Router(); | ||
1 | const request = require('request'); | 3 | const request = require('request'); |
2 | const moment = require('moment'); | 4 | const moment = require('moment'); |
3 | require('moment-timezone'); | 5 | require('moment-timezone'); |
... | @@ -43,14 +45,20 @@ function get_base_time() // 시간 추출 함수 | ... | @@ -43,14 +45,20 @@ function get_base_time() // 시간 추출 함수 |
43 | return time | 45 | return time |
44 | } | 46 | } |
45 | 47 | ||
46 | -request({ | 48 | +router.get("/", (req, res) =>{ |
47 | - url: url + queryParams, | 49 | + request( |
48 | - method: 'GET' | 50 | + {url: url + queryParams, |
49 | -}, function (error, response, body) { | 51 | + method: 'GET', |
50 | - console.log('Status', response.statusCode); | 52 | + }, |
51 | - console.log('Headers', JSON.stringify(response.headers)); | 53 | + (error, response, body) => { |
52 | - console.log('Reponse received', body); | 54 | + console.log('Status', response.statusCode); |
53 | -}); | 55 | + console.log('Headers', JSON.stringify(response.headers)); |
56 | + console.log('Reponse received', body); | ||
57 | + } | ||
58 | + ); | ||
59 | +}); | ||
60 | + | ||
61 | +module.exports = router; | ||
54 | 62 | ||
55 | // | 63 | // |
56 | // (사용 예) | 64 | // (사용 예) | ... | ... |
router/user.js
0 → 100644
1 | +const express = require("express"); | ||
2 | +const router = express.Router(); | ||
3 | + | ||
4 | +router.get("/", function (req, res, next) { | ||
5 | + res.json([ | ||
6 | + { id: 1, username: "VictorOladipo" }, | ||
7 | + { id: 2, username: "RussellWstbrook" }, | ||
8 | + ]); | ||
9 | +}); | ||
10 | + | ||
11 | +module.exports = router; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
run_server.js
deleted
100644 → 0
1 | -// 서비스 제공을 위한 html 홈페이지를 express로 구현하기 (기본적인 뼈대) | ||
2 | -var express = require('express') | ||
3 | -var app = express(); // express 선언 | ||
4 | -const port = 10000 //임의의 포트 10000 | ||
5 | - | ||
6 | -// request 와 response 라는 인자를 줘서 콜백 함수를 만든다. | ||
7 | -// localhost:port 브라우저에 res.sendFile() 내부의 파일이 띄워진다. | ||
8 | -app.use(express.static(__dirname + "/html")); | ||
9 | - | ||
10 | -app.get('/', function(req,res) { | ||
11 | - res.sendFile(__dirname + "/html/index.html") | ||
12 | -}) | ||
13 | - | ||
14 | -//임의의 포트 10000, 접속 주소 localhost:10000/ | ||
15 | -app.listen(port, function(){ | ||
16 | - console.log('서버 구동중 port : %d', port); | ||
17 | -}); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -2,8 +2,17 @@ const express = require('express'); | ... | @@ -2,8 +2,17 @@ const express = require('express'); |
2 | const app = express(); | 2 | const app = express(); |
3 | const port = 5000; | 3 | const port = 5000; |
4 | const test = require('../router/test'); | 4 | const test = require('../router/test'); |
5 | +const weather = require('../router/Weather'); | ||
6 | +const user = require('../router/user'); | ||
7 | +const bodyParser = require('body-parser'); | ||
8 | +const cors = require('cors'); | ||
9 | + | ||
10 | +app.use(cors()); | ||
11 | +app.use("/test", test); | ||
12 | +app.use("/weather", weather); | ||
13 | +app.use("/user", user); | ||
14 | +app.use(bodyParser.json()); | ||
5 | 15 | ||
6 | -app.use("/api", test); | ||
7 | 16 | ||
8 | 17 | ||
9 | app.listen(port, ()=> console.log('Server is running on :', port)); | 18 | app.listen(port, ()=> console.log('Server is running on :', port)); |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment