diff --git a/server/app.js b/server/app.js index 1547830..6d4628a 100644 --- a/server/app.js +++ b/server/app.js @@ -6,7 +6,6 @@ import cookieParser from 'cookie-parser'; import apiRouter from './router/api'; import ssrRouter from './router/ssr'; - const __dirname = path.resolve(); const app = express(); @@ -38,7 +37,6 @@ app.use(express.static('public')); app.use('/api', apiRouter); app.use('/', ssrRouter); - app.listen(3000, () => { console.log('listen to http://localhost:3000'); }); diff --git a/server/router/api.js b/server/router/api.js index 6ddd6b2..ba5e660 100644 --- a/server/router/api.js +++ b/server/router/api.js @@ -8,21 +8,21 @@ const router = express.Router(); const upload = multer({ dest: '../uploads/' }); -const DEFAULT_HOST = 'http://ec2-15-165-61-122.ap-northeast-2.compute.amazonaws.com'; +const DEFAULT_HOST = 'http://52.79.66.109:8080'; const PREFIX = '/api/v1'; const ROOT_URL = DEFAULT_HOST + PREFIX; export function getAuthorizationCookie(req) { const accessToken = req.cookies.authorization; if (accessToken === undefined) return 'null'; - return accessToken; + return `Bearer ${accessToken}`; } export async function validateAccessToken(req) { const accessToken = getAuthorizationCookie(req); if (accessToken === undefined) return false; try { - await axios.get(`${ROOT_URL}/auth/check-atk`, { + await axios.get(`${ROOT_URL}/auth/token`, { headers: { Authorization: accessToken, }, @@ -46,22 +46,24 @@ export async function parsePDF(formData) { return response.data; } -export async function validateStudentNumber(formData) { - const response = await axios.post(`${ROOT_URL}/users/studentNumber-validity-checks`, formData); - return !response.data.isNotDuplicated; +export async function validateStudentNumber({ studentNumber }) { + const response = await axios.get( + `${ROOT_URL}/users/sign-up/check-duplicate-student-number?student-number=${studentNumber}` + ); + return !response.data.notDuplicated; } -export async function validateUserId(formData) { - const response = await axios.post(`${ROOT_URL}/users/userid-validity-checks`, formData); - return !response.data.isNotDuplicated; +export async function validateUserId({ userId }) { + const response = await axios.get(`${ROOT_URL}/users/sign-up/check-duplicate-auth-id?auth-id=${userId}`); + return !response.data.notDuplicated; } function apiErrorHandler(res, error) { - if (error.response.data.code) { + if (error.response?.data.status) { return res.status(400).json(error.response.data); } return res.status(500).json({ - code: 500, + status: 500, message: '서버에 장애가 있습니다.', }); } @@ -72,10 +74,9 @@ router.post('/file-upload', upload.single('file'), async function (req, res) { try { const pdfText = await parsePDF(formData); - const accessToken = getAuthorizationCookie(req); const response = await axios.post( - `${ROOT_URL}/users/me/taken-lectures`, + `${ROOT_URL}/parsing-text`, { parsingText: pdfText, }, @@ -93,22 +94,16 @@ router.post('/file-upload', upload.single('file'), async function (req, res) { router.post('/signin', async function (req, res) { const formData = { - userId: req.body.id, + authId: req.body.authId, password: req.body.password, }; try { const result = await axios.post(`${ROOT_URL}/auth/sign-in`, formData); - res.cookie('authorization', result.headers.authorization, { + res.cookie('authorization', `${result.data.accessToken}`, { httpOnly: true, }); - - const response = await axios.get(`${ROOT_URL}/users/me/init`, { - headers: { - Authorization: result.headers.authorization, - }, - }); - res.status(200).json({ isInit: response.data.init }); + res.status(200).json({ isInit: false }); } catch (error) { apiErrorHandler(res, error); } @@ -124,7 +119,7 @@ router.get('/signout', function (req, res) { router.post('/signup', async function (req, res) { const formData = { - userId: req.body.id, + authId: req.body.id, password: req.body.password, studentNumber: req.body.studentId, engLv: req.body.englishLevel, @@ -133,17 +128,17 @@ router.post('/signup', async function (req, res) { try { if (await validateUserId({ userId: req.body.id })) return res.status(400).json({ - code: 400, + status: 400, message: '이미 아이디가 존재합니다.', }); if (await validateStudentNumber({ studentNumber: req.body.studentId })) return res.status(400).json({ - code: 400, + status: 400, message: '이미 등록된 학번입니다.', }); - const result = await axios.post(`${ROOT_URL}/auth/sign-up`, formData); + const result = await axios.post(`${ROOT_URL}/users/sign-up`, formData); res.status(200).end(); } catch (error) { apiErrorHandler(res, error); @@ -151,12 +146,10 @@ router.post('/signup', async function (req, res) { }); router.post('/secession', async function (req, res) { - const formData = { - password: req.body.password, - }; const accessToken = getAuthorizationCookie(req); try { - const result = await axios.post(`${ROOT_URL}/users/leave`, formData, { + const result = await axios.delete(`${ROOT_URL}/users/me`, { + data: { password: req.body.password }, headers: { Authorization: accessToken, }, @@ -169,11 +162,11 @@ router.post('/secession', async function (req, res) { router.post('/userConfirm', async function (req, res) { const formData = { - userId: req.body.id, + authId: req.body.authId, studentNumber: req.body.studentNumber, }; try { - await axios.post(`${ROOT_URL}/users/pwinquiry`, formData, { + await axios.get(`${ROOT_URL}/users/${formData.studentNumber}/validate?auth-id=${formData.authId}`, formData, { headers: { 'Content-Type': 'application/json', }, @@ -195,7 +188,7 @@ router.get('/check-atk', async function (req, res) { router.get('/takenLectures', async function (req, res) { try { const accessToken = getAuthorizationCookie(req); - const result = await axios.get(`${ROOT_URL}/users/me/taken-lectures`, { + const result = await axios.get(`${ROOT_URL}/taken-lectures`, { headers: { Authorization: accessToken, }, @@ -205,26 +198,6 @@ router.get('/takenLectures', async function (req, res) { apiErrorHandler(res, error); } }); -router.get('/curriculumInfos', async function (req, res) { - try { - const lectureResult = await axios.get(`${ROOT_URL}/bachelor-info/lectures`, { - headers: { - 'Content-Type': 'application/json', - }, - params: req.query, - }); - const creditResult = await axios.get(`${ROOT_URL}/bachelor-info/requirement`, { - headers: { - // Authorization: accessToken, - 'Content-Type': 'application/json', - }, - params: req.query, - }); - res.json([creditResult.data, lectureResult.data]); - } catch (error) { - apiErrorHandler(res, error); - } -}); router.get('/search-lecture', async function (req, res) { try { @@ -236,7 +209,7 @@ router.get('/search-lecture', async function (req, res) { params: req.query, }); res.status(200).json({ - searchedLectures: response.data, + searchedLectures: response.data.lectures, }); } catch (error) { apiErrorHandler(res, error); @@ -251,7 +224,7 @@ router.post('/update-lecture', async function (req, res) { try { const accessToken = getAuthorizationCookie(req); - const result = await axios.patch(`${ROOT_URL}/users/me/taken-lectures`, formData, { + const result = await axios.post(`${ROOT_URL}/taken-lectures/update`, formData, { headers: { Authorization: accessToken, }, @@ -268,11 +241,11 @@ router.get('/myInfo', async function (req, res) { const accessToken = getAuthorizationCookie(req); if (accessToken === 'null') { res.status(500).json({ - code: 500, + status: 500, message: '서버에 장애가 있습니다.', }); } else { - const result = await axios.get(`${ROOT_URL}/users/me/information`, { + const result = await axios.get(`${ROOT_URL}/users/me`, { headers: { Authorization: accessToken, }, @@ -301,7 +274,7 @@ router.get('/graduation-result', async function (req, res) { router.get('/findId', async function (req, res) { try { const path = req._parsedUrl.query; - const response = await axios.get(`${ROOT_URL}/users/by/student-number/${path}`, { + const response = await axios.get(`${ROOT_URL}/users/${path}/auth-id`, { headers: { 'Content-Type': 'application/json', }, @@ -314,12 +287,12 @@ router.get('/findId', async function (req, res) { router.post('/findPw', async function (req, res) { const formData = { - userId: req.body.userId, + authId: req.body.authId, newPassword: req.body.newPassword, passwordCheck: req.body.passwordCheck, }; try { - const result = await axios.post(`${ROOT_URL}/users/reset-pw`, formData); + const result = await axios.patch(`${ROOT_URL}/users/password`, formData); res.status(200).end(); } catch (error) { apiErrorHandler(res, error); @@ -330,18 +303,8 @@ router.get('/check-user', async function (req, res) { const accessToken = req.cookies.authorization; if (accessToken === undefined) { res.status(400).end(); - } else { - try { - const response = await axios.get(`${ROOT_URL}/users/me/init`, { - headers: { - Authorization: accessToken, - }, - }); - res.status(200).json(response.data); - } catch (error) { - apiErrorHandler(res, error); - } } + res.status(200).json({ validToken: true, init: false }); }); export default router; diff --git a/src/async/auth.js b/src/async/auth.js index c454fe2..50dfb3c 100644 --- a/src/async/auth.js +++ b/src/async/auth.js @@ -15,10 +15,6 @@ export async function fetchSignIn(formData) { if (response.status === 200) { signIn(); - const result = await response.json(); - if (result.isInit) { - init(); - } return true; } @@ -135,31 +131,22 @@ export async function fetchValidateATK() { } export async function fetchValidateUser() { - const response = await fetch('/api/check-user'); + const response = await fetch('/api/myInfo'); if (response.status === 200) { const result = await response.json(); - - if (result.validToken) { - signIn(); - } else { - signOut(); - } - - if (result.init) { + if (!result.studentName) { init(); - } else { - unInit(); + return { init: true }; } - - return result; + unInit(); + return { init: false }; } signOut(); unInit(); return { - validToken: false, - init: false, + init: true, }; } diff --git a/src/async/file.js b/src/async/file.js index 5ed58b6..6ac167f 100644 --- a/src/async/file.js +++ b/src/async/file.js @@ -5,7 +5,6 @@ export async function fetchPDFFileUpload(formData) { method: 'POST', body: formData, }); - if (response.status === 400 || response.status === 500) { throw await makeError(response); } diff --git a/src/async/lecture.js b/src/async/lecture.js index 9b439d5..74a176e 100644 --- a/src/async/lecture.js +++ b/src/async/lecture.js @@ -10,7 +10,7 @@ export async function fetchGetSearchedLecture(query) { if (response.status === 400 || response.status === 500) { const result = await response.json(); const error = new Error(result.message); - error.code = result.code; + error.status = result.status; throw error; } @@ -45,20 +45,3 @@ export async function fetchGetTakenLectures() { const result = await response.json(); return result; } - -export async function fetchCurriculumInfos(query) { - const queryString = objectToQueryString(query); - - const response = await fetch(`/api/curriculumInfos?${queryString}`, { - headers: { - 'Content-Type': 'application/json', - }, - }); - - if (response.status === 400 || response.status === 500) { - throw await makeError(response); - } - const result = await response.json(); - - return result; -} diff --git a/src/components/GNB/GNB.component.js b/src/components/GNB/GNB.component.js index c90b5dd..e2bae12 100644 --- a/src/components/GNB/GNB.component.js +++ b/src/components/GNB/GNB.component.js @@ -60,7 +60,6 @@ export default class GNB extends Component {