Skip to content

Commit

Permalink
Merge pull request #7 from EntryDSM/develop
Browse files Browse the repository at this point in the history
모노레포 병합 전 병합
  • Loading branch information
dutexion authored Jul 29, 2024
2 parents 4275cf9 + 5c24444 commit d722ab9
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 21 deletions.
1 change: 1 addition & 0 deletions config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const { merge } = require('webpack-merge');

const path = require('path');
const common = require('./webpack.common');
const developmentConfig = require('./webpack.dev');
const productionConfig = require('./webpack.prod');
Expand Down
13 changes: 13 additions & 0 deletions config/webpack.dev.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const webpack = require('webpack');
const path = require('path');

module.exports = {
mode: 'development',
Expand All @@ -23,6 +24,18 @@ module.exports = {
'process.env.REACT_APP_BASE_URL': JSON.stringify(
process.env.REACT_APP_BASE_URL,
),
'process.env.REACT_APP_MAIN_URL': JSON.stringify(
process.env.REACT_APP_MAIN_URL,
),
'process.env.REACT_APP_AUTH_URL': JSON.stringify(
process.env.REACT_APP_AUTH_URL,
),
'process.env.REACT_APP_APPLY_URL': JSON.stringify(
process.env.REACT_APP_APPLY_URL,
),
'process.env.REACT_APP_ADMIN_URL': JSON.stringify(
process.env.REACT_APP_ADMIN_URL,
),
}),
],
module: {
Expand Down
28 changes: 26 additions & 2 deletions config/webpack.prod.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const webpack = require('webpack');
const path = require('path');

module.exports = {
mode: 'production',
Expand All @@ -10,7 +11,7 @@ module.exports = {
port: 3000,
historyApiFallback: true,
liveReload: true,
allowedHosts: "all"
allowedHosts: 'all',
},
output: {
filename: '[name].[contenthash].js',
Expand All @@ -22,7 +23,19 @@ module.exports = {
}),
new webpack.DefinePlugin({
'process.env.REACT_APP_BASE_URL': JSON.stringify(
process.env.REACT_APP_BASE_URL,
process.env.REACT_APP_BASE_URL,
),
'process.env.REACT_APP_MAIN_URL': JSON.stringify(
process.env.REACT_APP_MAIN_URL,
),
'process.env.REACT_APP_AUTH_URL': JSON.stringify(
process.env.REACT_APP_AUTH_URL,
),
'process.env.REACT_APP_APPLY_URL': JSON.stringify(
process.env.REACT_APP_APPLY_URL,
),
'process.env.REACT_APP_ADMIN_URL': JSON.stringify(
process.env.REACT_APP_ADMIN_URL,
),
}),
],
Expand All @@ -39,4 +52,15 @@ module.exports = {
maxEntrypointSize: 512000,
maxAssetSize: 512000,
},
devServer: {
historyApiFallback: true,
static: {
directory: path.resolve(__dirname, '../dist'),
},
open: true,
compress: true,
hot: true,
port: 3000,
allowedHosts: 'all',
},
};
4 changes: 4 additions & 0 deletions src/@types/react.app-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@ declare namespace NodeJS {
NODE_ENV: 'development' | 'production' | 'test';
PUBLIC_URL: string;
REACT_APP_BASE_URL: string;
REACT_APP_MAIN_URL: string;
REACT_APP_AUTH_URL: string;
REACT_APP_APPLY_URL: string;
REACT_APP_ADMIN_URL: string;
}
}
16 changes: 12 additions & 4 deletions src/apis/adminLogin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ import { useMutation } from 'react-query';
import { instance } from './axios';
import { setCookies, setTokens } from '@/utils/cookies';
import { AuthResponse } from './login';
import { COOKIE_DOMAIN } from '@/constant/env';
import { ADMIN_URL, COOKIE_DOMAIN, MAIN_URL } from '@/constant/env';
import { AxiosError } from 'axios';
import { Toast } from '@team-entry/design_system';
import { checkLocalPort } from '@/utils/checkLocalPort';

interface AdminLoginProps {
adminId: string;
password: string;
}

export const useAdminLogin = (redirectURL: string) => {
export const useAdminLogin = () => {
return useMutation(
({ adminId, password }: AdminLoginProps) =>
instance.post<AuthResponse>('/admin/auth', {
Expand All @@ -35,8 +36,15 @@ export const useAdminLogin = (redirectURL: string) => {
Toast('로그인에 실패하였습니다.', { type: 'error' });
}
},
onSuccess: (res) => {
window.location.href = 'https://admin.entrydsm.hs.kr';
onSuccess: async (res) => {
let redirectUrl: string;
if (COOKIE_DOMAIN === 'localhost') {
const isLocalPortOpen = await checkLocalPort(3001);
redirectUrl = isLocalPortOpen ? ADMIN_URL : MAIN_URL;
} else {
redirectUrl = ADMIN_URL;
}
window.location.href = redirectUrl;
setTokens(res.data.accessToken, res.data.refreshToken);
setCookies('authority', 'admin', {
path: '/',
Expand Down
4 changes: 2 additions & 2 deletions src/components/GoToAuthorization.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useOpenPopUp } from '@/apis/popup';
import { BASE_URL } from '@/constant/env';
import { AUTH_URL } from '@/constant/env';
import styled from '@emotion/styled';
import { Button, Text } from '@team-entry/design_system';

Expand All @@ -10,7 +10,7 @@ interface Props {
export const GoToAuthorization = ({ text }: Props) => {
const { openPopUp } = useOpenPopUp();
const goToAuthorization = () => {
openPopUp.mutate(`${BASE_URL}/verify`);
openPopUp.mutate(`${AUTH_URL}/verify`);
};

return (
Expand Down
18 changes: 8 additions & 10 deletions src/constant/env.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
export const BASE_URL =
process.env.NODE_ENV === 'development'
? 'http://localhost:3000'
: 'https://auth.entrydsm.hs.kr';

export const MAIN_URL =
process.env.NODE_ENV === 'development'
? 'http://localhost:3002'
: 'https://www.entrydsm.hs.kr';

export const COOKIE_DOMAIN =
process.env.NODE_ENV === 'development' ? 'localhost' : 'entrydsm.hs.kr';

export const MAIN_URL = process.env.REACT_APP_MAIN_URL;

export const AUTH_URL = process.env.REACT_APP_AUTH_URL;

export const APPLY_URL = process.env.REACT_APP_APPLY_URL;

export const ADMIN_URL = process.env.REACT_APP_ADMIN_URL;
2 changes: 1 addition & 1 deletion src/pages/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const Login = ({ redirectURL, isAdmin = false }: ILogin) => {
});

const { mutate: userLogin } = useLogin(redirectURL);
const { mutate: adminLogin } = useAdminLogin(redirectURL);
const { mutate: adminLogin } = useAdminLogin();

return (
<SubmitForm>
Expand Down
4 changes: 2 additions & 2 deletions src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import { NotFound } from './pages/404';
import { Pass } from './components/Pass';
import { Verify } from './pages/Verify';
import { getQueryValues } from './utils/getQueryValues';
import { MAIN_URL } from './constant/env';

export const Router = () => {
const redirectURL =
getQueryValues().get('redirect_url') || 'https://www.entrydsm.hs.kr';
const redirectURL = getQueryValues().get('redirect_url') || `${MAIN_URL}`;

return (
<BrowserRouter>
Expand Down
8 changes: 8 additions & 0 deletions src/utils/checkLocalPort.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const checkLocalPort = async (port: number): Promise<boolean> => {
try {
const response = await fetch(`http://localhost:${port}`);
return response.status === 200;
} catch (error) {
return false;
}
};

0 comments on commit d722ab9

Please sign in to comment.