HyeonJun Jeon

[Style] Use env

......@@ -22,4 +22,4 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*
.prettierignore
*.pvdata
.env
......
......@@ -15,6 +15,7 @@
"body-parser": "^1.20.0",
"cors": "^2.8.5",
"crypto-js": "^4.1.1",
"dotenv": "^16.0.1",
"express": "^4.18.1",
"fs": "^0.0.1-security",
"localforage": "^1.10.0",
......@@ -6398,11 +6399,11 @@
}
},
"node_modules/dotenv": {
"version": "10.0.0",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz",
"integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==",
"version": "16.0.1",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.1.tgz",
"integrity": "sha512-1K6hR6wtk2FviQ4kEiSjFiH5rpzEVi8WW0x96aztHVMhEspNpc4DVOUTEHtEva5VThQ8IaBX1Pe4gSzpVVUsKQ==",
"engines": {
"node": ">=10"
"node": ">=12"
}
},
"node_modules/dotenv-expand": {
......@@ -14041,6 +14042,14 @@
}
}
},
"node_modules/react-scripts/node_modules/dotenv": {
"version": "10.0.0",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz",
"integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==",
"engines": {
"node": ">=10"
}
},
"node_modules/readable-stream": {
"version": "3.6.0",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz",
......@@ -21350,9 +21359,9 @@
}
},
"dotenv": {
"version": "10.0.0",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz",
"integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q=="
"version": "16.0.1",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.1.tgz",
"integrity": "sha512-1K6hR6wtk2FviQ4kEiSjFiH5rpzEVi8WW0x96aztHVMhEspNpc4DVOUTEHtEva5VThQ8IaBX1Pe4gSzpVVUsKQ=="
},
"dotenv-expand": {
"version": "5.1.0",
......@@ -26761,6 +26770,13 @@
"webpack-dev-server": "^4.6.0",
"webpack-manifest-plugin": "^4.0.2",
"workbox-webpack-plugin": "^6.4.1"
},
"dependencies": {
"dotenv": {
"version": "10.0.0",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz",
"integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q=="
}
}
},
"readable-stream": {
......
......@@ -10,6 +10,7 @@
"body-parser": "^1.20.0",
"cors": "^2.8.5",
"crypto-js": "^4.1.1",
"dotenv": "^16.0.1",
"express": "^4.18.1",
"fs": "^0.0.1-security",
"localforage": "^1.10.0",
......
const mysql2 = require("mysql2/promise");
const fs = require("fs");
const [id, pw] = fs
.readFileSync("server/libs/sql.pvdata", "utf8")
.split("\r\n");
const connectOption = {
host: "extended-calendar-db.cihyg6ssq3la.ap-northeast-2.rds.amazonaws.com",
user: id,
password: pw,
database: "db",
require("dotenv").config();
const poolOptions = {
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_DATABASE,
};
const pool = mysql2.createPool(connectOption);
const pool = mysql2.createPool(poolOptions);
async function jcalToSQL(jcal, userID) {
const connection = await pool.getConnection(async (con) => con);
......@@ -65,4 +63,4 @@ async function jcalToSQL(jcal, userID) {
// iCal의 소유주를 DB에 등록 후 userID get
// subjectID가 subjects, userID가 users에 있어야함
module.exports = { jcalToSQL, connectOption, pool };
module.exports = { jcalToSQL, pool };
......
......@@ -5,11 +5,5 @@ const router = express.Router();
const { login } = require("./E_Campus.js");
const parseICal = require("./ICal.js");
async function runrun() {
const mdata = await axios.get("http://localhost:3001/db/users", {params:{loginID:"good1588"}}
)
console.log(mdata.data)
}
async function runrun() {}
runrun();
......
......@@ -5,6 +5,7 @@ const router = express.Router();
const { login } = require("../libs/E_Campus.js");
const parseICal = require("../libs/ICal.js");
const { jcalToSQL } = require("../libs/MySQL.js");
require("dotenv").config();
// (id, pw) => failed | error | {peed, subjects, name, ID}
router.post("/", async (req, res) => {
......@@ -14,22 +15,28 @@ router.post("/", async (req, res) => {
try {
const { peed, subjects } = result;
const resUser = await axios.post("http://3.34.173.161:3001/db/users", {
const resUser = await axios.post(
`http://${process.env.SERVER_IP}:3001/db/users`,
{
loginID: req.body.id,
loginPW: req.body.pw,
ical: peed,
});
}
);
const userID = resUser.data.ID;
const { data: subList } = await axios.post(
"http://3.34.173.161:3001/db/subjects/s",
`http://${process.env.SERVER_IP}:3001/db/subjects/s`,
{
list: subjects,
}
);
await axios.post("http://3.34.173.161:3001/db/user-subject/s", {
await axios.post(
`http://${process.env.SERVER_IP}:3001/db/user-subject/s`,
{
userID,
subList,
});
}
);
const { data: ical } = await axios({
url: peed,
method: "GET",
......
const express = require("express");
const fs = require("fs");
const cors = require("cors");
const loginRouter = require("./routers/Login");
......@@ -10,7 +9,7 @@ const app = express();
app.use(
cors({
origin: "http://3.34.173.161:3000",
origin: `http://${process.env.REACT_APP_IP}:3000`,
credentials: true,
})
);
......@@ -20,27 +19,9 @@ app.use(express.urlencoded({ extended: true }));
app.use("/login", loginRouter);
app.use("/db", dbRouter);
// 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(express.static(path.join(__dirname, "../build")));
app.get("*", function (요청, 응답) {
응답.sendFile(path.join(__dirname, "../build/index.html"));
app.get("*", function (req, res) {
res.sendFile(path.join(__dirname, "../build/index.html"));
});
app.listen(3001, function () {
......
......@@ -30,15 +30,15 @@ const GridItem = ({ targetDate }) => {
day: targetDate.getDay(),
};
const { data: scdate } = await axios.get(
"http://3.34.173.161:3001/db/schedules_date",
`http://${process.env.REACT_APP_SERVER_IP}:3001/db/schedules_date`,
{ params }
);
const { data: sctime } = await axios.get(
"http://3.34.173.161:3001/db/schedules_time",
`http://${process.env.REACT_APP_SERVER_IP}:3001/db/schedules_time`,
{ params }
);
const { data: scrpeat } = await axios.get(
"http://3.34.173.161:3001/db/schedules_repeat",
`http://${process.env.REACT_APP_SERVER_IP}:3001/db/schedules_repeat`,
{ params }
);
const subs = await localforage.getItem("subjects");
......@@ -58,13 +58,16 @@ const GridItem = ({ targetDate }) => {
const finishSchedule = async (table, uid) => {
for (const i in schedules)
if (schedules[i].uid === uid) {
await axios.delete("http://3.34.173.161:3001/db/schedule", {
await axios.delete(
`http://${process.env.REACT_APP_SERVER_IP}:3001/db/schedule`,
{
data: {
table,
uid,
userID: await localforage.getItem("userID"),
},
});
}
);
schedules.splice(i, 1);
setSchedules(schedules);
}
......@@ -81,7 +84,7 @@ const GridItem = ({ targetDate }) => {
const table =
state.startTime || state.endTime ? "schedules_time" : "schedules_date";
const { data: sche } = await axios.post(
"http://3.34.173.161:3001/db/" + table,
`http://${process.env.REACT_APP_SERVER_IP}:3001/db/` + table,
{
userID: await localforage.getItem("userID"),
...state,
......
......@@ -75,7 +75,7 @@ const ScheduleItem = ({ schedule, finish }) => {
<div className="spl">
<span>{subjectName}</span>
{url ? (
<a href={url} target="_blank">
<a href={url} target="_blank" rel="noreferrer">
{label}
</a>
) : (
......
......@@ -19,22 +19,28 @@ const render = (subsObj, args) => {
case "CHECKED":
sub = subsObj[args.subjectID];
sub.status = !sub.status;
axios.put("http://3.34.173.161:3001/db/user-subject/check", {
axios.put(
`http://${process.env.REACT_APP_SERVER_IP}:3001/db/user-subject/check`,
{
userID: sub.userID,
subjectID: args.subjectID,
status: +sub.status,
});
}
);
return { ...subsObj, [args.subjectID]: sub };
case "MODIFY":
sub = subsObj[args.subjectID];
sub.nickname = args.nickname;
sub.color = args.color;
axios.put("http://3.34.173.161:3001/db/user-subject/modify", {
axios.put(
`http://${process.env.REACT_APP_SERVER_IP}:3001/db/user-subject/modify`,
{
userID: sub.userID,
subjectID: args.subjectID,
nickname: sub.nickname,
color: sub.color,
});
}
);
return { ...subsObj, [args.subjectID]: sub };
case "INIT":
return args.subsObj;
......@@ -59,7 +65,7 @@ const Calendar = () => {
// get user's subjects
const userID = await localforage.getItem("userID");
const { data: subjects } = await axios.get(
"http://3.34.173.161:3001/db/user-subject",
`http://${process.env.REACT_APP_SERVER_IP}:3001/db/user-subject`,
{ params: { userID } }
);
await localforage.setItem("subjects", subjects);
......
import axios from "axios";
// import axios from "axios";
import { useState } from "react";
import { useNavigate } from "react-router-dom";
//import { login } from "../libs/E_Campus";
......@@ -31,7 +31,7 @@ const Debug = () => {
// case "server":
// setState({ ...state, output: "loading..." });
// axios
// .post("http://3.34.173.161:3001/login/", {
// .post(`http://${process.env.REACT_APP_SERVER_IP}:3001/login/`, {
// id: state.input1,
// pw: state.input2,
// })
......
......@@ -25,23 +25,26 @@ const Login = () => {
const login = async () => {
setState({ ...state, btn: "Login..." });
const { data: userDBID } = await axios.get(
"http://3.34.173.161:3001/db/users",
`http://${process.env.REACT_APP_SERVER_IP}:3001/db/users`,
{ params: { loginID: state.id } }
);
if (userDBID) {
//pass crawling, just ical
const { data: peed } = await axios.get(
"http://3.34.173.161:3001/db/users/ical",
`http://${process.env.REACT_APP_SERVER_IP}:3001/db/users/ical`,
{ params: { ID: userDBID } }
);
await axios.put("http://3.34.173.161:3001/db/ical", {
await axios.put(
`http://${process.env.REACT_APP_SERVER_IP}:3001/db/ical`,
{
userID: userDBID,
peed: peed.ical,
});
}
);
const hashpw = cryptoJs.SHA256(state.pw).toString();
const { data: isCorrectPW } = await axios.get(
"http://3.34.173.161:3001/db/users/check",
`http://${process.env.REACT_APP_SERVER_IP}:3001/db/users/check`,
{
params: { loginID: state.id, loginPW: hashpw },
}
......@@ -57,7 +60,7 @@ const Login = () => {
} else {
//crawling
const { data: loginResult } = await axios.post(
"http://3.34.173.161:3001/login/",
`http://${process.env.REACT_APP_SERVER_IP}:3001/login/`,
{
id: state.id,
pw: state.pw,
......