HyeonJun Jeon

[Implement] Sync with server

...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
12 "@testing-library/react": "^13.2.0", 12 "@testing-library/react": "^13.2.0",
13 "@testing-library/user-event": "^13.5.0", 13 "@testing-library/user-event": "^13.5.0",
14 "axios": "^0.27.2", 14 "axios": "^0.27.2",
15 + "body-parser": "^1.20.0",
16 + "cors": "^2.8.5",
15 "express": "^4.18.1", 17 "express": "^4.18.1",
16 "fs": "^0.0.1-security", 18 "fs": "^0.0.1-security",
17 "localforage": "^1.10.0", 19 "localforage": "^1.10.0",
...@@ -5568,6 +5570,18 @@ ...@@ -5568,6 +5570,18 @@
5568 "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", 5570 "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz",
5569 "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==" 5571 "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ=="
5570 }, 5572 },
5573 + "node_modules/cors": {
5574 + "version": "2.8.5",
5575 + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz",
5576 + "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==",
5577 + "dependencies": {
5578 + "object-assign": "^4",
5579 + "vary": "^1"
5580 + },
5581 + "engines": {
5582 + "node": ">= 0.10"
5583 + }
5584 + },
5571 "node_modules/cosmiconfig": { 5585 "node_modules/cosmiconfig": {
5572 "version": "7.0.1", 5586 "version": "7.0.1",
5573 "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-7.0.1.tgz", 5587 "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-7.0.1.tgz",
...@@ -20602,6 +20616,15 @@ ...@@ -20602,6 +20616,15 @@
20602 "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", 20616 "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz",
20603 "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==" 20617 "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ=="
20604 }, 20618 },
20619 + "cors": {
20620 + "version": "2.8.5",
20621 + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz",
20622 + "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==",
20623 + "requires": {
20624 + "object-assign": "^4",
20625 + "vary": "^1"
20626 + }
20627 + },
20605 "cosmiconfig": { 20628 "cosmiconfig": {
20606 "version": "7.0.1", 20629 "version": "7.0.1",
20607 "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-7.0.1.tgz", 20630 "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-7.0.1.tgz",
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
7 "@testing-library/react": "^13.2.0", 7 "@testing-library/react": "^13.2.0",
8 "@testing-library/user-event": "^13.5.0", 8 "@testing-library/user-event": "^13.5.0",
9 "axios": "^0.27.2", 9 "axios": "^0.27.2",
10 + "body-parser": "^1.20.0",
11 + "cors": "^2.8.5",
10 "express": "^4.18.1", 12 "express": "^4.18.1",
11 "fs": "^0.0.1-security", 13 "fs": "^0.0.1-security",
12 "localforage": "^1.10.0", 14 "localforage": "^1.10.0",
...@@ -22,7 +24,7 @@ ...@@ -22,7 +24,7 @@
22 "build": "react-scripts build", 24 "build": "react-scripts build",
23 "test": "react-scripts test", 25 "test": "react-scripts test",
24 "eject": "react-scripts eject", 26 "eject": "react-scripts eject",
25 - "server": "nodemon server/server.js" 27 + "server": "nodemon -w ./server server/server.js"
26 }, 28 },
27 "eslintConfig": { 29 "eslintConfig": {
28 "extends": [ 30 "extends": [
......
...@@ -39,7 +39,7 @@ async function login(id, pw) { ...@@ -39,7 +39,7 @@ async function login(id, pw) {
39 ) { 39 ) {
40 return false; 40 return false;
41 } else { 41 } else {
42 - // await page.goto('https://khcanvas.khu.ac.kr'); 42 + // 내 강의실
43 let selector = 43 let selector =
44 "#visual > div > div.xn-main-login-container > div:nth-child(2) > div.xn-main-link-wrap.xn-main-lms-link-wrap > a"; 44 "#visual > div > div.xn-main-login-container > div:nth-child(2) > div.xn-main-link-wrap.xn-main-lms-link-wrap > a";
45 await page.waitForSelector(selector); 45 await page.waitForSelector(selector);
...@@ -50,16 +50,13 @@ async function login(id, pw) { ...@@ -50,16 +50,13 @@ async function login(id, pw) {
50 } catch (err) { 50 } catch (err) {
51 console.log(err); 51 console.log(err);
52 } 52 }
53 - return result;
54 } 53 }
55 54
56 //function that get your peed for your Ecampus calendar 55 //function that get your peed for your Ecampus calendar
57 async function getPeed(page) { 56 async function getPeed(page) {
58 - console.log("getPeed");
59 -
60 selector = "#global_nav_calendar_link > div.menu-item-icon-container > svg"; 57 selector = "#global_nav_calendar_link > div.menu-item-icon-container > svg";
61 await page.waitForSelector(selector); 58 await page.waitForSelector(selector);
62 - await page.click(selector); 59 + await Promise.all([page.click(selector), page.waitForNavigation()]);
63 60
64 selector = "#calendar-feed > button"; 61 selector = "#calendar-feed > button";
65 await page.waitForSelector(selector); 62 await page.waitForSelector(selector);
...@@ -86,7 +83,6 @@ async function getPeed(page) { ...@@ -86,7 +83,6 @@ async function getPeed(page) {
86 } 83 }
87 84
88 async function getSubjects(page) { 85 async function getSubjects(page) {
89 - console.log("getSubjects");
90 await page.click( 86 await page.click(
91 "#global_nav_courses_link > div.menu-item-icon-container > svg" 87 "#global_nav_courses_link > div.menu-item-icon-container > svg"
92 ); 88 );
......
1 +const express = require("express");
2 +const router = express.Router();
3 +
4 +const { getPeed, getSubjects, login } = require("../libs/E_Campus.js");
5 +
6 +router.post("/", async (req, res) => {
7 + console.log(`listened /login ${req.body.id} ${req.body.pw}`);
8 + const page = await login(req.body.id, req.body.pw);
9 + if (page) {
10 + const peed = await getPeed(page);
11 + res.send(peed);
12 + } else res.send("failed");
13 +});
14 +
15 +module.exports = router;
1 const express = require("express"); 1 const express = require("express");
2 -const { getPeed, getSubjects, login } = require("./libs/E_Campus.js"); 2 +const bodyParser = require("body-parser");
3 const fs = require("fs"); 3 const fs = require("fs");
4 +const cors = require("cors");
5 +const { getPeed, getSubjects, login } = require("./libs/E_Campus.js");
6 +
7 +const loginRouter = require("./routers/login");
4 8
5 const app = express(); 9 const app = express();
6 -const router = express.Router();
7 10
8 -router.get("/", (req, res) => { 11 +app.use(
9 - console.log(req); 12 + cors({
10 - res.header("Access-Control-Allow-Origin", "http://localhost:3000"); 13 + origin: "http://localhost:3000",
11 - res.send({ test: "Hi" }); 14 + credentials: true,
15 + })
16 +);
17 +app.use(bodyParser.urlencoded({ extended: false }));
18 +app.use(bodyParser.json());
19 +
20 +app.post("/", (req, res) => {
21 + res.send({ body: req.body });
12 console.log("listened /"); 22 console.log("listened /");
13 }); 23 });
14 24
15 -app.use("/", router); 25 +app.use("/login", loginRouter);
16 - 26 +
17 -fs.readFile("server/libs/login.pvdata", "utf8", async (err, data) => { 27 +// fs.readFile("server/libs/login.pvdata", "utf8", async (err, data) => {
18 - if (err) { 28 +// if (err) {
19 - console.error(err); 29 +// console.error(err);
20 - console.log("server/libs/login.pvdata에 ID\\nPW를 작성"); 30 +// console.log("server/libs/login.pvdata에 ID\\nPW를 작성");
21 - return; 31 +// return;
22 - } 32 +// }
23 - const page = await login(...data.split("\r\n")); 33 +// const page = await login(...data.split("\r\n"));
24 - if (page) { 34 +// if (page) {
25 - const feed = await getPeed(page); 35 +// const feed = await getPeed(page);
26 - const subjects = await getSubjects(page); 36 +// const subjects = await getSubjects(page);
27 - console.log({ feed, subjects }); 37 +// console.log({ feed, subjects });
28 -
29 - app.listen(3001, function () {
30 - console.log("listening on 3001");
31 - });
32 - } else console.log("Incorrect user ID or password.");
33 -});
34 38
35 -// app.listen(3001, function () { 39 +// app.listen(3001, function () {
36 -// console.log("listening on 3001"); 40 +// console.log("listening on 3001");
41 +// });
42 +// } else console.log("Incorrect user ID or password.");
37 // }); 43 // });
44 +
45 +app.listen(3001, function () {
46 + console.log("listening on 3001");
47 +});
......
...@@ -35,8 +35,13 @@ const Debug = () => { ...@@ -35,8 +35,13 @@ const Debug = () => {
35 break; 35 break;
36 case "server": 36 case "server":
37 axios 37 axios
38 - .get("http://localhost:3001/") 38 + .post("http://localhost:3001/login/", {
39 - .then((res) => setState({ ...state, output: res.data.test })); 39 + id: state.input1,
40 + pw: state.input2,
41 + })
42 + .then((res) => {
43 + setState({ ...state, output: res.data });
44 + });
40 return; 45 return;
41 default: 46 default:
42 } 47 }
......