육현진

Api module, proxy

This diff is collapsed. Click to expand it.
...@@ -45,6 +45,23 @@ const students = [ ...@@ -45,6 +45,23 @@ const students = [
45 }] 45 }]
46 46
47 class App extends Component{ 47 class App extends Component{
48 +
49 + state = {
50 + students: ""
51 + }
52 +
53 + componentDidMount() {
54 + this.callApi()
55 + .then(res => this.setState({students: res}))
56 + .catch(err => console.log(err));
57 + }
58 +
59 + callApi=async()=>{
60 + const response = await fetch('/api/students');
61 + const body = await response.json();
62 + return body;
63 + }
64 +
48 render(){ 65 render(){
49 66
50 const {classes}= this.props; 67 const {classes}= this.props;
...@@ -54,6 +71,7 @@ class App extends Component{ ...@@ -54,6 +71,7 @@ class App extends Component{
54 <Table className={classes.table}> 71 <Table className={classes.table}>
55 72
56 <TableHead> 73 <TableHead>
74 + <TableRow>
57 <TableCell>코드번호</TableCell> 75 <TableCell>코드번호</TableCell>
58 <TableCell>이름</TableCell> 76 <TableCell>이름</TableCell>
59 <TableCell>학번</TableCell> 77 <TableCell>학번</TableCell>
...@@ -63,11 +81,13 @@ class App extends Component{ ...@@ -63,11 +81,13 @@ class App extends Component{
63 <TableCell>과제</TableCell> 81 <TableCell>과제</TableCell>
64 <TableCell>출석</TableCell> 82 <TableCell>출석</TableCell>
65 <TableCell>학점</TableCell> 83 <TableCell>학점</TableCell>
84 + </TableRow>
66 </TableHead> 85 </TableHead>
67 86
68 <TableBody> 87 <TableBody>
69 { 88 {
70 - students.map(c=>{ 89 + this.state.students ?
90 + this.state.students.map(c=>{
71 return ( 91 return (
72 <Student 92 <Student
73 key={c.st_Code} 93 key={c.st_Code}
...@@ -82,7 +102,7 @@ class App extends Component{ ...@@ -82,7 +102,7 @@ class App extends Component{
82 st_Score={c.st_Score} 102 st_Score={c.st_Score}
83 /> 103 />
84 ); 104 );
85 - }) 105 + }) : ""
86 } 106 }
87 </TableBody> 107 </TableBody>
88 108
......
1 +const proxy = require("http-proxy-middleware");
2 +
3 +module.exports = function(app) {
4 + app.use(proxy("/api/students", { target: "http://localhost:5000" }));
5 +};
...\ No newline at end of file ...\ No newline at end of file
1 { 1 {
2 - "name": "Student", 2 + "name": "student_management",
3 "version": "1.0.0", 3 "version": "1.0.0",
4 "lockfileVersion": 1, 4 "lockfileVersion": 1,
5 "requires": true, 5 "requires": true,
6 "dependencies": { 6 "dependencies": {
7 + "@types/http-proxy": {
8 + "version": "1.17.4",
9 + "resolved": "https://registry.npmjs.org/@types/http-proxy/-/http-proxy-1.17.4.tgz",
10 + "integrity": "sha512-IrSHl2u6AWXduUaDLqYpt45tLVCtYv7o4Z0s1KghBCDgIIS9oW5K1H8mZG/A2CfeLdEa7rTd1ACOiHBc1EMT2Q==",
11 + "requires": {
12 + "@types/node": "*"
13 + }
14 + },
15 + "@types/node": {
16 + "version": "14.14.10",
17 + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.10.tgz",
18 + "integrity": "sha512-J32dgx2hw8vXrSbu4ZlVhn1Nm3GbeCFNw2FWL8S5QKucHGY0cyNwjdQdO+KMBZ4wpmC7KhLCiNsdk1RFRIYUQQ=="
19 + },
7 "accepts": { 20 "accepts": {
8 "version": "1.3.7", 21 "version": "1.3.7",
9 "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz", 22 "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz",
...@@ -50,6 +63,14 @@ ...@@ -50,6 +63,14 @@
50 "type-is": "~1.6.17" 63 "type-is": "~1.6.17"
51 } 64 }
52 }, 65 },
66 + "braces": {
67 + "version": "3.0.2",
68 + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz",
69 + "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==",
70 + "requires": {
71 + "fill-range": "^7.0.1"
72 + }
73 + },
53 "bytes": { 74 "bytes": {
54 "version": "3.1.0", 75 "version": "3.1.0",
55 "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz", 76 "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz",
...@@ -220,6 +241,11 @@ ...@@ -220,6 +241,11 @@
220 "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", 241 "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz",
221 "integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=" 242 "integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc="
222 }, 243 },
244 + "eventemitter3": {
245 + "version": "4.0.7",
246 + "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz",
247 + "integrity": "sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw=="
248 + },
223 "express": { 249 "express": {
224 "version": "4.17.1", 250 "version": "4.17.1",
225 "resolved": "https://registry.npmjs.org/express/-/express-4.17.1.tgz", 251 "resolved": "https://registry.npmjs.org/express/-/express-4.17.1.tgz",
...@@ -257,6 +283,14 @@ ...@@ -257,6 +283,14 @@
257 "vary": "~1.1.2" 283 "vary": "~1.1.2"
258 } 284 }
259 }, 285 },
286 + "fill-range": {
287 + "version": "7.0.1",
288 + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz",
289 + "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==",
290 + "requires": {
291 + "to-regex-range": "^5.0.1"
292 + }
293 + },
260 "finalhandler": { 294 "finalhandler": {
261 "version": "1.1.2", 295 "version": "1.1.2",
262 "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.2.tgz", 296 "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.2.tgz",
...@@ -280,6 +314,11 @@ ...@@ -280,6 +314,11 @@
280 "locate-path": "^3.0.0" 314 "locate-path": "^3.0.0"
281 } 315 }
282 }, 316 },
317 + "follow-redirects": {
318 + "version": "1.13.0",
319 + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.0.tgz",
320 + "integrity": "sha512-aq6gF1BEKje4a9i9+5jimNFIpq4Q1WiwBToeRK5NvZBd/TRsmW8BsJfOEGkr76TbOyPVD3OVDN910EcUNtRYEA=="
321 + },
283 "forwarded": { 322 "forwarded": {
284 "version": "0.1.2", 323 "version": "0.1.2",
285 "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz", 324 "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz",
...@@ -335,6 +374,28 @@ ...@@ -335,6 +374,28 @@
335 "toidentifier": "1.0.0" 374 "toidentifier": "1.0.0"
336 } 375 }
337 }, 376 },
377 + "http-proxy": {
378 + "version": "1.18.1",
379 + "resolved": "https://registry.npmjs.org/http-proxy/-/http-proxy-1.18.1.tgz",
380 + "integrity": "sha512-7mz/721AbnJwIVbnaSv1Cz3Am0ZLT/UBwkC92VlxhXv/k/BBQfM2fXElQNC27BVGr0uwUpplYPQM9LnaBMR5NQ==",
381 + "requires": {
382 + "eventemitter3": "^4.0.0",
383 + "follow-redirects": "^1.0.0",
384 + "requires-port": "^1.0.0"
385 + }
386 + },
387 + "http-proxy-middleware": {
388 + "version": "1.0.6",
389 + "resolved": "https://registry.npmjs.org/http-proxy-middleware/-/http-proxy-middleware-1.0.6.tgz",
390 + "integrity": "sha512-NyL6ZB6cVni7pl+/IT2W0ni5ME00xR0sN27AQZZrpKn1b+qRh+mLbBxIq9Cq1oGfmTc7BUq4HB77mxwCaxAYNg==",
391 + "requires": {
392 + "@types/http-proxy": "^1.17.4",
393 + "http-proxy": "^1.18.1",
394 + "is-glob": "^4.0.1",
395 + "lodash": "^4.17.20",
396 + "micromatch": "^4.0.2"
397 + }
398 + },
338 "iconv-lite": { 399 "iconv-lite": {
339 "version": "0.4.24", 400 "version": "0.4.24",
340 "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", 401 "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
...@@ -368,12 +429,30 @@ ...@@ -368,12 +429,30 @@
368 "has": "^1.0.3" 429 "has": "^1.0.3"
369 } 430 }
370 }, 431 },
432 + "is-extglob": {
433 + "version": "2.1.1",
434 + "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz",
435 + "integrity": "sha1-qIwCU1eR8C7TfHahueqXc8gz+MI="
436 + },
371 "is-fullwidth-code-point": { 437 "is-fullwidth-code-point": {
372 "version": "2.0.0", 438 "version": "2.0.0",
373 "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", 439 "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz",
374 "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=", 440 "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=",
375 "dev": true 441 "dev": true
376 }, 442 },
443 + "is-glob": {
444 + "version": "4.0.1",
445 + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.1.tgz",
446 + "integrity": "sha512-5G0tKtBTFImOqDnLB2hG6Bp2qcKEFduo4tZu9MT/H6NQv/ghhy30o55ufafxJ/LdH79LLs2Kfrn85TLKyA7BUg==",
447 + "requires": {
448 + "is-extglob": "^2.1.1"
449 + }
450 + },
451 + "is-number": {
452 + "version": "7.0.0",
453 + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz",
454 + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng=="
455 + },
377 "json-parse-better-errors": { 456 "json-parse-better-errors": {
378 "version": "1.0.2", 457 "version": "1.0.2",
379 "resolved": "https://registry.npmjs.org/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz", 458 "resolved": "https://registry.npmjs.org/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz",
...@@ -393,8 +472,7 @@ ...@@ -393,8 +472,7 @@
393 "lodash": { 472 "lodash": {
394 "version": "4.17.20", 473 "version": "4.17.20",
395 "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz", 474 "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz",
396 - "integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==", 475 + "integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA=="
397 - "dev": true
398 }, 476 },
399 "media-typer": { 477 "media-typer": {
400 "version": "0.3.0", 478 "version": "0.3.0",
...@@ -411,6 +489,15 @@ ...@@ -411,6 +489,15 @@
411 "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", 489 "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz",
412 "integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4=" 490 "integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4="
413 }, 491 },
492 + "micromatch": {
493 + "version": "4.0.2",
494 + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.2.tgz",
495 + "integrity": "sha512-y7FpHSbMUMoyPbYUSzO6PaZ6FyRnQOpHuKwbo1G+Knck95XVU4QAiKdGEnj5wwoS7PlOgthX/09u5iFJ+aYf5Q==",
496 + "requires": {
497 + "braces": "^3.0.1",
498 + "picomatch": "^2.0.5"
499 + }
500 + },
414 "mime": { 501 "mime": {
415 "version": "1.6.0", 502 "version": "1.6.0",
416 "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", 503 "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz",
...@@ -515,6 +602,11 @@ ...@@ -515,6 +602,11 @@
515 "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", 602 "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz",
516 "integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w=" 603 "integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w="
517 }, 604 },
605 + "picomatch": {
606 + "version": "2.2.2",
607 + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.2.2.tgz",
608 + "integrity": "sha512-q0M/9eZHzmr0AulXyPwNfZjtwZ/RBZlbN3K3CErVrk50T2ASYI7Bye0EvekFY3IP1Nt2DHu0re+V2ZHIpMkuWg=="
609 + },
518 "pify": { 610 "pify": {
519 "version": "3.0.0", 611 "version": "3.0.0",
520 "resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz", 612 "resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz",
...@@ -574,6 +666,11 @@ ...@@ -574,6 +666,11 @@
574 "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==", 666 "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==",
575 "dev": true 667 "dev": true
576 }, 668 },
669 + "requires-port": {
670 + "version": "1.0.0",
671 + "resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz",
672 + "integrity": "sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8="
673 + },
577 "resolve": { 674 "resolve": {
578 "version": "1.19.0", 675 "version": "1.19.0",
579 "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.19.0.tgz", 676 "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.19.0.tgz",
...@@ -730,6 +827,14 @@ ...@@ -730,6 +827,14 @@
730 "has-flag": "^3.0.0" 827 "has-flag": "^3.0.0"
731 } 828 }
732 }, 829 },
830 + "to-regex-range": {
831 + "version": "5.0.1",
832 + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz",
833 + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==",
834 + "requires": {
835 + "is-number": "^7.0.0"
836 + }
837 + },
733 "toidentifier": { 838 "toidentifier": {
734 "version": "1.0.0", 839 "version": "1.0.0",
735 "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz", 840 "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz",
......
1 { 1 {
2 - "name": "Student", 2 + "name": "student_management",
3 "version": "1.0.0", 3 "version": "1.0.0",
4 "scripts": { 4 "scripts": {
5 "client": "cd client && npm start", 5 "client": "cd client && npm start",
6 "server": "nodemon server.js", 6 "server": "nodemon server.js",
7 - "dev": "concurrently --kill-others-on-fail \"yarn server\" \"yarn client\"" 7 + "dev": "concurrently --kill-others-on-fail \"npm run server\" \"npm run client\""
8 }, 8 },
9 "dependencies": { 9 "dependencies": {
10 "body-parser": "^1.19.0", 10 "body-parser": "^1.19.0",
11 - "express": "4.17.1" 11 + "express": "4.17.1",
12 + "http-proxy-middleware": "^1.0.6"
12 }, 13 },
13 "devDependencies": { 14 "devDependencies": {
14 "concurrently": "^5.3.0" 15 "concurrently": "^5.3.0"
......
...@@ -6,8 +6,31 @@ const port = process.env.process || 5000; ...@@ -6,8 +6,31 @@ const port = process.env.process || 5000;
6 app.use(bodyparser.json()); 6 app.use(bodyparser.json());
7 app.use(bodyparser.urlencoded({ extended: true})); 7 app.use(bodyparser.urlencoded({ extended: true}));
8 8
9 -app.get('/api/hello', (req, res)=>{ 9 +app.get('/api/students', (req, res)=>{
10 - res.send({message: 'Hello Express!'}); 10 + res.send([
11 + {
12 + 'st_Code': 6666,
13 + 'st_Name': '육현진',
14 + 'st_Id': 2018102210,
15 + 'st_Major':'컴퓨터공학과',
16 + 'st_Midscore': 100,
17 + 'st_Finalscore': 100,
18 + 'st_Assignscore': 100,
19 + 'st_Attendscore': 100,
20 + 'st_Score':'A+'
21 + },
22 + {
23 + 'st_Code': 1111,
24 + 'st_Name': '김창동',
25 + 'st_Id': 2020021120,
26 + 'st_Major':'컴퓨터공학과',
27 + 'st_Midscore': 79,
28 + 'st_Finalscore': 85,
29 + 'st_Assignscore': 100,
30 + 'st_Attendscore': 90,
31 + 'st_Score':'A0'
32 + }
33 + ]);
11 }); 34 });
12 35
13 app.listen(port, () => console.log(`Listening on port ${port}`)); 36 app.listen(port, () => console.log(`Listening on port ${port}`));
...\ No newline at end of file ...\ No newline at end of file
......