HyeonJun Jeon

[Implement] Sync with server

......@@ -12,6 +12,8 @@
"@testing-library/react": "^13.2.0",
"@testing-library/user-event": "^13.5.0",
"axios": "^0.27.2",
"body-parser": "^1.20.0",
"cors": "^2.8.5",
"express": "^4.18.1",
"fs": "^0.0.1-security",
"localforage": "^1.10.0",
......@@ -5568,6 +5570,18 @@
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz",
"integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ=="
},
"node_modules/cors": {
"version": "2.8.5",
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz",
"integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==",
"dependencies": {
"object-assign": "^4",
"vary": "^1"
},
"engines": {
"node": ">= 0.10"
}
},
"node_modules/cosmiconfig": {
"version": "7.0.1",
"resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-7.0.1.tgz",
......@@ -20602,6 +20616,15 @@
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz",
"integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ=="
},
"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"
}
},
"cosmiconfig": {
"version": "7.0.1",
"resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-7.0.1.tgz",
......
......@@ -7,6 +7,8 @@
"@testing-library/react": "^13.2.0",
"@testing-library/user-event": "^13.5.0",
"axios": "^0.27.2",
"body-parser": "^1.20.0",
"cors": "^2.8.5",
"express": "^4.18.1",
"fs": "^0.0.1-security",
"localforage": "^1.10.0",
......@@ -22,7 +24,7 @@
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"server": "nodemon server/server.js"
"server": "nodemon -w ./server server/server.js"
},
"eslintConfig": {
"extends": [
......
......@@ -39,7 +39,7 @@ async function login(id, pw) {
) {
return false;
} else {
// await page.goto('https://khcanvas.khu.ac.kr');
// 내 강의실
let selector =
"#visual > div > div.xn-main-login-container > div:nth-child(2) > div.xn-main-link-wrap.xn-main-lms-link-wrap > a";
await page.waitForSelector(selector);
......@@ -50,16 +50,13 @@ async function login(id, pw) {
} catch (err) {
console.log(err);
}
return result;
}
//function that get your peed for your Ecampus calendar
async function getPeed(page) {
console.log("getPeed");
selector = "#global_nav_calendar_link > div.menu-item-icon-container > svg";
await page.waitForSelector(selector);
await page.click(selector);
await Promise.all([page.click(selector), page.waitForNavigation()]);
selector = "#calendar-feed > button";
await page.waitForSelector(selector);
......@@ -86,7 +83,6 @@ async function getPeed(page) {
}
async function getSubjects(page) {
console.log("getSubjects");
await page.click(
"#global_nav_courses_link > div.menu-item-icon-container > svg"
);
......
const express = require("express");
const router = express.Router();
const { getPeed, getSubjects, login } = require("../libs/E_Campus.js");
router.post("/", async (req, res) => {
console.log(`listened /login ${req.body.id} ${req.body.pw}`);
const page = await login(req.body.id, req.body.pw);
if (page) {
const peed = await getPeed(page);
res.send(peed);
} else res.send("failed");
});
module.exports = router;
const express = require("express");
const { getPeed, getSubjects, login } = require("./libs/E_Campus.js");
const bodyParser = require("body-parser");
const fs = require("fs");
const cors = require("cors");
const { getPeed, getSubjects, login } = require("./libs/E_Campus.js");
const loginRouter = require("./routers/login");
const app = express();
const router = express.Router();
router.get("/", (req, res) => {
console.log(req);
res.header("Access-Control-Allow-Origin", "http://localhost:3000");
res.send({ test: "Hi" });
app.use(
cors({
origin: "http://localhost:3000",
credentials: true,
})
);
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.post("/", (req, res) => {
res.send({ body: req.body });
console.log("listened /");
});
app.use("/", router);
fs.readFile("server/libs/login.pvdata", "utf8", async (err, data) => {
if (err) {
console.error(err);
console.log("server/libs/login.pvdata에 ID\\nPW를 작성");
return;
}
const page = await login(...data.split("\r\n"));
if (page) {
const feed = await getPeed(page);
const subjects = await getSubjects(page);
console.log({ feed, subjects });
app.listen(3001, function () {
console.log("listening on 3001");
});
} else console.log("Incorrect user ID or password.");
});
app.use("/login", loginRouter);
// fs.readFile("server/libs/login.pvdata", "utf8", async (err, data) => {
// if (err) {
// console.error(err);
// console.log("server/libs/login.pvdata에 ID\\nPW를 작성");
// return;
// }
// const page = await login(...data.split("\r\n"));
// if (page) {
// const feed = await getPeed(page);
// const subjects = await getSubjects(page);
// console.log({ feed, subjects });
// app.listen(3001, function () {
// console.log("listening on 3001");
// });
// } else console.log("Incorrect user ID or password.");
// });
app.listen(3001, function () {
console.log("listening on 3001");
});
......
......@@ -35,8 +35,13 @@ const Debug = () => {
break;
case "server":
axios
.get("http://localhost:3001/")
.then((res) => setState({ ...state, output: res.data.test }));
.post("http://localhost:3001/login/", {
id: state.input1,
pw: state.input2,
})
.then((res) => {
setState({ ...state, output: res.data });
});
return;
default:
}
......