HyeonJun Jeon

[Style] Use env

...@@ -22,4 +22,4 @@ npm-debug.log* ...@@ -22,4 +22,4 @@ npm-debug.log*
22 yarn-debug.log* 22 yarn-debug.log*
23 yarn-error.log* 23 yarn-error.log*
24 .prettierignore 24 .prettierignore
25 -*.pvdata 25 +.env
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
15 "body-parser": "^1.20.0", 15 "body-parser": "^1.20.0",
16 "cors": "^2.8.5", 16 "cors": "^2.8.5",
17 "crypto-js": "^4.1.1", 17 "crypto-js": "^4.1.1",
18 + "dotenv": "^16.0.1",
18 "express": "^4.18.1", 19 "express": "^4.18.1",
19 "fs": "^0.0.1-security", 20 "fs": "^0.0.1-security",
20 "localforage": "^1.10.0", 21 "localforage": "^1.10.0",
...@@ -6398,11 +6399,11 @@ ...@@ -6398,11 +6399,11 @@
6398 } 6399 }
6399 }, 6400 },
6400 "node_modules/dotenv": { 6401 "node_modules/dotenv": {
6401 - "version": "10.0.0", 6402 + "version": "16.0.1",
6402 - "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz", 6403 + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.1.tgz",
6403 - "integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==", 6404 + "integrity": "sha512-1K6hR6wtk2FviQ4kEiSjFiH5rpzEVi8WW0x96aztHVMhEspNpc4DVOUTEHtEva5VThQ8IaBX1Pe4gSzpVVUsKQ==",
6404 "engines": { 6405 "engines": {
6405 - "node": ">=10" 6406 + "node": ">=12"
6406 } 6407 }
6407 }, 6408 },
6408 "node_modules/dotenv-expand": { 6409 "node_modules/dotenv-expand": {
...@@ -14041,6 +14042,14 @@ ...@@ -14041,6 +14042,14 @@
14041 } 14042 }
14042 } 14043 }
14043 }, 14044 },
14045 + "node_modules/react-scripts/node_modules/dotenv": {
14046 + "version": "10.0.0",
14047 + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz",
14048 + "integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==",
14049 + "engines": {
14050 + "node": ">=10"
14051 + }
14052 + },
14044 "node_modules/readable-stream": { 14053 "node_modules/readable-stream": {
14045 "version": "3.6.0", 14054 "version": "3.6.0",
14046 "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", 14055 "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz",
...@@ -21350,9 +21359,9 @@ ...@@ -21350,9 +21359,9 @@
21350 } 21359 }
21351 }, 21360 },
21352 "dotenv": { 21361 "dotenv": {
21353 - "version": "10.0.0", 21362 + "version": "16.0.1",
21354 - "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz", 21363 + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.1.tgz",
21355 - "integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==" 21364 + "integrity": "sha512-1K6hR6wtk2FviQ4kEiSjFiH5rpzEVi8WW0x96aztHVMhEspNpc4DVOUTEHtEva5VThQ8IaBX1Pe4gSzpVVUsKQ=="
21356 }, 21365 },
21357 "dotenv-expand": { 21366 "dotenv-expand": {
21358 "version": "5.1.0", 21367 "version": "5.1.0",
...@@ -26761,6 +26770,13 @@ ...@@ -26761,6 +26770,13 @@
26761 "webpack-dev-server": "^4.6.0", 26770 "webpack-dev-server": "^4.6.0",
26762 "webpack-manifest-plugin": "^4.0.2", 26771 "webpack-manifest-plugin": "^4.0.2",
26763 "workbox-webpack-plugin": "^6.4.1" 26772 "workbox-webpack-plugin": "^6.4.1"
26773 + },
26774 + "dependencies": {
26775 + "dotenv": {
26776 + "version": "10.0.0",
26777 + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz",
26778 + "integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q=="
26779 + }
26764 } 26780 }
26765 }, 26781 },
26766 "readable-stream": { 26782 "readable-stream": {
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
10 "body-parser": "^1.20.0", 10 "body-parser": "^1.20.0",
11 "cors": "^2.8.5", 11 "cors": "^2.8.5",
12 "crypto-js": "^4.1.1", 12 "crypto-js": "^4.1.1",
13 + "dotenv": "^16.0.1",
13 "express": "^4.18.1", 14 "express": "^4.18.1",
14 "fs": "^0.0.1-security", 15 "fs": "^0.0.1-security",
15 "localforage": "^1.10.0", 16 "localforage": "^1.10.0",
......
1 const mysql2 = require("mysql2/promise"); 1 const mysql2 = require("mysql2/promise");
2 -const fs = require("fs");
3 2
4 -const [id, pw] = fs 3 +require("dotenv").config();
5 - .readFileSync("server/libs/sql.pvdata", "utf8") 4 +
6 - .split("\r\n"); 5 +const poolOptions = {
7 -const connectOption = { 6 + host: process.env.DB_HOST,
8 - host: "extended-calendar-db.cihyg6ssq3la.ap-northeast-2.rds.amazonaws.com", 7 + user: process.env.DB_USER,
9 - user: id, 8 + password: process.env.DB_PASSWORD,
10 - password: pw, 9 + database: process.env.DB_DATABASE,
11 - database: "db",
12 }; 10 };
13 -const pool = mysql2.createPool(connectOption); 11 +const pool = mysql2.createPool(poolOptions);
14 12
15 async function jcalToSQL(jcal, userID) { 13 async function jcalToSQL(jcal, userID) {
16 const connection = await pool.getConnection(async (con) => con); 14 const connection = await pool.getConnection(async (con) => con);
...@@ -65,4 +63,4 @@ async function jcalToSQL(jcal, userID) { ...@@ -65,4 +63,4 @@ async function jcalToSQL(jcal, userID) {
65 // iCal의 소유주를 DB에 등록 후 userID get 63 // iCal의 소유주를 DB에 등록 후 userID get
66 // subjectID가 subjects, userID가 users에 있어야함 64 // subjectID가 subjects, userID가 users에 있어야함
67 65
68 -module.exports = { jcalToSQL, connectOption, pool }; 66 +module.exports = { jcalToSQL, pool };
......
...@@ -5,11 +5,5 @@ const router = express.Router(); ...@@ -5,11 +5,5 @@ const router = express.Router();
5 const { login } = require("./E_Campus.js"); 5 const { login } = require("./E_Campus.js");
6 const parseICal = require("./ICal.js"); 6 const parseICal = require("./ICal.js");
7 7
8 -async function runrun() { 8 +async function runrun() {}
9 -
10 - const mdata = await axios.get("http://localhost:3001/db/users", {params:{loginID:"good1588"}}
11 -
12 - )
13 - console.log(mdata.data)
14 -}
15 runrun(); 9 runrun();
......
...@@ -5,6 +5,7 @@ const router = express.Router(); ...@@ -5,6 +5,7 @@ const router = express.Router();
5 const { login } = require("../libs/E_Campus.js"); 5 const { login } = require("../libs/E_Campus.js");
6 const parseICal = require("../libs/ICal.js"); 6 const parseICal = require("../libs/ICal.js");
7 const { jcalToSQL } = require("../libs/MySQL.js"); 7 const { jcalToSQL } = require("../libs/MySQL.js");
8 +require("dotenv").config();
8 9
9 // (id, pw) => failed | error | {peed, subjects, name, ID} 10 // (id, pw) => failed | error | {peed, subjects, name, ID}
10 router.post("/", async (req, res) => { 11 router.post("/", async (req, res) => {
...@@ -14,22 +15,28 @@ router.post("/", async (req, res) => { ...@@ -14,22 +15,28 @@ router.post("/", async (req, res) => {
14 try { 15 try {
15 const { peed, subjects } = result; 16 const { peed, subjects } = result;
16 17
17 - const resUser = await axios.post("http://3.34.173.161:3001/db/users", { 18 + const resUser = await axios.post(
19 + `http://${process.env.SERVER_IP}:3001/db/users`,
20 + {
18 loginID: req.body.id, 21 loginID: req.body.id,
19 loginPW: req.body.pw, 22 loginPW: req.body.pw,
20 ical: peed, 23 ical: peed,
21 - }); 24 + }
25 + );
22 const userID = resUser.data.ID; 26 const userID = resUser.data.ID;
23 const { data: subList } = await axios.post( 27 const { data: subList } = await axios.post(
24 - "http://3.34.173.161:3001/db/subjects/s", 28 + `http://${process.env.SERVER_IP}:3001/db/subjects/s`,
25 { 29 {
26 list: subjects, 30 list: subjects,
27 } 31 }
28 ); 32 );
29 - await axios.post("http://3.34.173.161:3001/db/user-subject/s", { 33 + await axios.post(
34 + `http://${process.env.SERVER_IP}:3001/db/user-subject/s`,
35 + {
30 userID, 36 userID,
31 subList, 37 subList,
32 - }); 38 + }
39 + );
33 const { data: ical } = await axios({ 40 const { data: ical } = await axios({
34 url: peed, 41 url: peed,
35 method: "GET", 42 method: "GET",
......
1 const express = require("express"); 1 const express = require("express");
2 -const fs = require("fs");
3 const cors = require("cors"); 2 const cors = require("cors");
4 3
5 const loginRouter = require("./routers/Login"); 4 const loginRouter = require("./routers/Login");
...@@ -10,7 +9,7 @@ const app = express(); ...@@ -10,7 +9,7 @@ const app = express();
10 9
11 app.use( 10 app.use(
12 cors({ 11 cors({
13 - origin: "http://3.34.173.161:3000", 12 + origin: `http://${process.env.REACT_APP_IP}:3000`,
14 credentials: true, 13 credentials: true,
15 }) 14 })
16 ); 15 );
...@@ -20,27 +19,9 @@ app.use(express.urlencoded({ extended: true })); ...@@ -20,27 +19,9 @@ app.use(express.urlencoded({ extended: true }));
20 app.use("/login", loginRouter); 19 app.use("/login", loginRouter);
21 app.use("/db", dbRouter); 20 app.use("/db", dbRouter);
22 21
23 -// fs.readFile("server/libs/login.pvdata", "utf8", async (err, data) => {
24 -// if (err) {
25 -// console.error(err);
26 -// console.log("server/libs/login.pvdata에 ID\\nPW를 작성");
27 -// return;
28 -// }
29 -// const page = await login(...data.split("\r\n"));
30 -// if (page) {
31 -// const feed = await getPeed(page);
32 -// const subjects = await getSubjects(page);
33 -// console.log({ feed, subjects });
34 -
35 -// app.listen(3001, function () {
36 -// console.log("listening on 3001");
37 -// });
38 -// } else console.log("Incorrect user ID or password.");
39 -// });
40 -
41 app.use(express.static(path.join(__dirname, "../build"))); 22 app.use(express.static(path.join(__dirname, "../build")));
42 -app.get("*", function (요청, 응답) { 23 +app.get("*", function (req, res) {
43 - 응답.sendFile(path.join(__dirname, "../build/index.html")); 24 + res.sendFile(path.join(__dirname, "../build/index.html"));
44 }); 25 });
45 26
46 app.listen(3001, function () { 27 app.listen(3001, function () {
......
...@@ -30,15 +30,15 @@ const GridItem = ({ targetDate }) => { ...@@ -30,15 +30,15 @@ const GridItem = ({ targetDate }) => {
30 day: targetDate.getDay(), 30 day: targetDate.getDay(),
31 }; 31 };
32 const { data: scdate } = await axios.get( 32 const { data: scdate } = await axios.get(
33 - "http://3.34.173.161:3001/db/schedules_date", 33 + `http://${process.env.REACT_APP_SERVER_IP}:3001/db/schedules_date`,
34 { params } 34 { params }
35 ); 35 );
36 const { data: sctime } = await axios.get( 36 const { data: sctime } = await axios.get(
37 - "http://3.34.173.161:3001/db/schedules_time", 37 + `http://${process.env.REACT_APP_SERVER_IP}:3001/db/schedules_time`,
38 { params } 38 { params }
39 ); 39 );
40 const { data: scrpeat } = await axios.get( 40 const { data: scrpeat } = await axios.get(
41 - "http://3.34.173.161:3001/db/schedules_repeat", 41 + `http://${process.env.REACT_APP_SERVER_IP}:3001/db/schedules_repeat`,
42 { params } 42 { params }
43 ); 43 );
44 const subs = await localforage.getItem("subjects"); 44 const subs = await localforage.getItem("subjects");
...@@ -58,13 +58,16 @@ const GridItem = ({ targetDate }) => { ...@@ -58,13 +58,16 @@ const GridItem = ({ targetDate }) => {
58 const finishSchedule = async (table, uid) => { 58 const finishSchedule = async (table, uid) => {
59 for (const i in schedules) 59 for (const i in schedules)
60 if (schedules[i].uid === uid) { 60 if (schedules[i].uid === uid) {
61 - await axios.delete("http://3.34.173.161:3001/db/schedule", { 61 + await axios.delete(
62 + `http://${process.env.REACT_APP_SERVER_IP}:3001/db/schedule`,
63 + {
62 data: { 64 data: {
63 table, 65 table,
64 uid, 66 uid,
65 userID: await localforage.getItem("userID"), 67 userID: await localforage.getItem("userID"),
66 }, 68 },
67 - }); 69 + }
70 + );
68 schedules.splice(i, 1); 71 schedules.splice(i, 1);
69 setSchedules(schedules); 72 setSchedules(schedules);
70 } 73 }
...@@ -81,7 +84,7 @@ const GridItem = ({ targetDate }) => { ...@@ -81,7 +84,7 @@ const GridItem = ({ targetDate }) => {
81 const table = 84 const table =
82 state.startTime || state.endTime ? "schedules_time" : "schedules_date"; 85 state.startTime || state.endTime ? "schedules_time" : "schedules_date";
83 const { data: sche } = await axios.post( 86 const { data: sche } = await axios.post(
84 - "http://3.34.173.161:3001/db/" + table, 87 + `http://${process.env.REACT_APP_SERVER_IP}:3001/db/` + table,
85 { 88 {
86 userID: await localforage.getItem("userID"), 89 userID: await localforage.getItem("userID"),
87 ...state, 90 ...state,
......
...@@ -75,7 +75,7 @@ const ScheduleItem = ({ schedule, finish }) => { ...@@ -75,7 +75,7 @@ const ScheduleItem = ({ schedule, finish }) => {
75 <div className="spl"> 75 <div className="spl">
76 <span>{subjectName}</span> 76 <span>{subjectName}</span>
77 {url ? ( 77 {url ? (
78 - <a href={url} target="_blank"> 78 + <a href={url} target="_blank" rel="noreferrer">
79 {label} 79 {label}
80 </a> 80 </a>
81 ) : ( 81 ) : (
......
...@@ -19,22 +19,28 @@ const render = (subsObj, args) => { ...@@ -19,22 +19,28 @@ const render = (subsObj, args) => {
19 case "CHECKED": 19 case "CHECKED":
20 sub = subsObj[args.subjectID]; 20 sub = subsObj[args.subjectID];
21 sub.status = !sub.status; 21 sub.status = !sub.status;
22 - axios.put("http://3.34.173.161:3001/db/user-subject/check", { 22 + axios.put(
23 + `http://${process.env.REACT_APP_SERVER_IP}:3001/db/user-subject/check`,
24 + {
23 userID: sub.userID, 25 userID: sub.userID,
24 subjectID: args.subjectID, 26 subjectID: args.subjectID,
25 status: +sub.status, 27 status: +sub.status,
26 - }); 28 + }
29 + );
27 return { ...subsObj, [args.subjectID]: sub }; 30 return { ...subsObj, [args.subjectID]: sub };
28 case "MODIFY": 31 case "MODIFY":
29 sub = subsObj[args.subjectID]; 32 sub = subsObj[args.subjectID];
30 sub.nickname = args.nickname; 33 sub.nickname = args.nickname;
31 sub.color = args.color; 34 sub.color = args.color;
32 - axios.put("http://3.34.173.161:3001/db/user-subject/modify", { 35 + axios.put(
36 + `http://${process.env.REACT_APP_SERVER_IP}:3001/db/user-subject/modify`,
37 + {
33 userID: sub.userID, 38 userID: sub.userID,
34 subjectID: args.subjectID, 39 subjectID: args.subjectID,
35 nickname: sub.nickname, 40 nickname: sub.nickname,
36 color: sub.color, 41 color: sub.color,
37 - }); 42 + }
43 + );
38 return { ...subsObj, [args.subjectID]: sub }; 44 return { ...subsObj, [args.subjectID]: sub };
39 case "INIT": 45 case "INIT":
40 return args.subsObj; 46 return args.subsObj;
...@@ -59,7 +65,7 @@ const Calendar = () => { ...@@ -59,7 +65,7 @@ const Calendar = () => {
59 // get user's subjects 65 // get user's subjects
60 const userID = await localforage.getItem("userID"); 66 const userID = await localforage.getItem("userID");
61 const { data: subjects } = await axios.get( 67 const { data: subjects } = await axios.get(
62 - "http://3.34.173.161:3001/db/user-subject", 68 + `http://${process.env.REACT_APP_SERVER_IP}:3001/db/user-subject`,
63 { params: { userID } } 69 { params: { userID } }
64 ); 70 );
65 await localforage.setItem("subjects", subjects); 71 await localforage.setItem("subjects", subjects);
......
1 -import axios from "axios"; 1 +// import axios from "axios";
2 import { useState } from "react"; 2 import { useState } from "react";
3 import { useNavigate } from "react-router-dom"; 3 import { useNavigate } from "react-router-dom";
4 //import { login } from "../libs/E_Campus"; 4 //import { login } from "../libs/E_Campus";
...@@ -31,7 +31,7 @@ const Debug = () => { ...@@ -31,7 +31,7 @@ const Debug = () => {
31 // case "server": 31 // case "server":
32 // setState({ ...state, output: "loading..." }); 32 // setState({ ...state, output: "loading..." });
33 // axios 33 // axios
34 - // .post("http://3.34.173.161:3001/login/", { 34 + // .post(`http://${process.env.REACT_APP_SERVER_IP}:3001/login/`, {
35 // id: state.input1, 35 // id: state.input1,
36 // pw: state.input2, 36 // pw: state.input2,
37 // }) 37 // })
......
...@@ -25,23 +25,26 @@ const Login = () => { ...@@ -25,23 +25,26 @@ const Login = () => {
25 const login = async () => { 25 const login = async () => {
26 setState({ ...state, btn: "Login..." }); 26 setState({ ...state, btn: "Login..." });
27 const { data: userDBID } = await axios.get( 27 const { data: userDBID } = await axios.get(
28 - "http://3.34.173.161:3001/db/users", 28 + `http://${process.env.REACT_APP_SERVER_IP}:3001/db/users`,
29 { params: { loginID: state.id } } 29 { params: { loginID: state.id } }
30 ); 30 );
31 if (userDBID) { 31 if (userDBID) {
32 //pass crawling, just ical 32 //pass crawling, just ical
33 const { data: peed } = await axios.get( 33 const { data: peed } = await axios.get(
34 - "http://3.34.173.161:3001/db/users/ical", 34 + `http://${process.env.REACT_APP_SERVER_IP}:3001/db/users/ical`,
35 { params: { ID: userDBID } } 35 { params: { ID: userDBID } }
36 ); 36 );
37 - await axios.put("http://3.34.173.161:3001/db/ical", { 37 + await axios.put(
38 + `http://${process.env.REACT_APP_SERVER_IP}:3001/db/ical`,
39 + {
38 userID: userDBID, 40 userID: userDBID,
39 peed: peed.ical, 41 peed: peed.ical,
40 - }); 42 + }
43 + );
41 44
42 const hashpw = cryptoJs.SHA256(state.pw).toString(); 45 const hashpw = cryptoJs.SHA256(state.pw).toString();
43 const { data: isCorrectPW } = await axios.get( 46 const { data: isCorrectPW } = await axios.get(
44 - "http://3.34.173.161:3001/db/users/check", 47 + `http://${process.env.REACT_APP_SERVER_IP}:3001/db/users/check`,
45 { 48 {
46 params: { loginID: state.id, loginPW: hashpw }, 49 params: { loginID: state.id, loginPW: hashpw },
47 } 50 }
...@@ -57,7 +60,7 @@ const Login = () => { ...@@ -57,7 +60,7 @@ const Login = () => {
57 } else { 60 } else {
58 //crawling 61 //crawling
59 const { data: loginResult } = await axios.post( 62 const { data: loginResult } = await axios.post(
60 - "http://3.34.173.161:3001/login/", 63 + `http://${process.env.REACT_APP_SERVER_IP}:3001/login/`,
61 { 64 {
62 id: state.id, 65 id: state.id,
63 pw: state.pw, 66 pw: state.pw,
......