diff --git a/.env b/.env new file mode 100644 index 0000000..1fec409 --- /dev/null +++ b/.env @@ -0,0 +1,2 @@ +REACT_APP_API_SERVER=http://localhost:4000 +DB_USER=root \ No newline at end of file diff --git a/.env.production b/.env.production new file mode 100644 index 0000000..5e3c068 --- /dev/null +++ b/.env.production @@ -0,0 +1 @@ +REACT_APP_API_SERVER=http://ec2-3-139-101-167.us-east-2.compute.amazonaws.com:80 \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 494b8bd..10f7baa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "@testing-library/user-event": "^12.8.3", "axios": "^0.21.1", "bootstrap": "^4.6.0", + "dotenv": "^8.2.0", "moment": "^2.29.1", "react": "^17.0.2", "react-bootstrap": "^1.5.2", diff --git a/package.json b/package.json index 5d47c0a..c8036ef 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "@testing-library/user-event": "^12.8.3", "axios": "^0.21.1", "bootstrap": "^4.6.0", + "dotenv": "^8.2.0", "moment": "^2.29.1", "react": "^17.0.2", "react-bootstrap": "^1.5.2", diff --git a/src/App.js b/src/App.js index eb86eec..e4deece 100644 --- a/src/App.js +++ b/src/App.js @@ -8,6 +8,7 @@ import Character1 from './images/Character1.png'; import { useHistory } from 'react-router-dom'; import './main.css'; import Bgm from './Bgm'; +require('dotenv').config(); const axios = require('axios'); @@ -46,8 +47,10 @@ export default function App() { const hendleLogout = () => { axios - .get('http://localhost:4000/user/logout', { withCredentials: true }) - .then((res) => {}); + .get( + `${process.env.REACT_APP_API_SERVER}/user/logout`, + {withCredentials: true} + ).then((res) => {}) setUserInfo({ id: null, nickname: null, @@ -64,7 +67,7 @@ export default function App() { const accessTokenRequest = (accessToken) => { // ! 유저 정보를 알려달라는 코드 axios - .get('http://localhost:4000/accessTokenHandler', { + .get(`${process.env.REACT_APP_API_SERVER}/accessTokenHandler`, { headers: { Authorization: `Bearer ${accessToken}`, 'Content-Type': 'application/json', @@ -72,10 +75,7 @@ export default function App() { withCredentials: true, }) .then((res) => { -<<<<<<< HEAD -======= const { nickname, email, profile_image, comment, id } = res.data.data; ->>>>>>> a5771eaba281de9abd8e0bf97642c16df821de90 // ! return res.data.data; }) @@ -101,7 +101,7 @@ export default function App() { const refreshTokenRequest = () => { // ! 일정 주기로 함수 계속 보냄 axios - .get('http://localhost:4000/refreshTokenHandler', { + .get(`${process.env.REACT_APP_API_SERVER}/refreshTokenHandler`, { withCredentials: true, }) .then((res) => { @@ -115,16 +115,7 @@ export default function App() { comment, } = res.data.data.userInfo; -<<<<<<< HEAD setAccessToken({ accessToken: res.data.data.accessToken }); -======= - - if (res.data.message !== 'ok') {} - const { nickname, email, profile_image, id,comment } = res.data.data.userInfo; - console.log(res.data.data.accessToken) - setAccessToken({accessToken:res.data.data.accessToken}) - ->>>>>>> a5771eaba281de9abd8e0bf97642c16df821de90 setUserInfo({ id: id, nickname: nickname, @@ -144,8 +135,9 @@ export default function App() { const getAccessToken = async (authorizationCode) => { // ! 구글 로그인 + console.log('ddddddddddddddddddddddddddddddddddddddddddldldldldldldldl') let resp = await axios.post( - 'http://localhost:4000/googlelogin', + `${process.env.REACT_APP_API_SERVER}/googlelogin`, { authorizationCode: authorizationCode, }, @@ -153,21 +145,12 @@ export default function App() { withCredentials: true, } ); -<<<<<<< HEAD - -======= ->>>>>>> a5771eaba281de9abd8e0bf97642c16df821de90 issueAccessToken(resp.data.accessToken); }; //구글 로그인 코드 받기-------------------------------- useEffect(() => { const url = new URL(window.location.href); const authorizationCode = url.searchParams.get('code'); -<<<<<<< HEAD - - console.log('userInfo:', userInfo); -======= ->>>>>>> a5771eaba281de9abd8e0bf97642c16df821de90 if (authorizationCode) { getAccessToken(authorizationCode); } diff --git a/src/GamePages/InGame.js b/src/GamePages/InGame.js index daca810..c51a9b3 100644 --- a/src/GamePages/InGame.js +++ b/src/GamePages/InGame.js @@ -11,7 +11,8 @@ import Words from '../Words'; import { useHistory } from 'react-router-dom'; import Logo from './components/Logo'; import Canvas from './components/Canvas3'; -const socket = io.connect('http://localhost:4000', { +require('dotenv').config(); +const socket = io.connect(`${process.env.REACT_APP_API_SERVER}`, { transports: ['websocket'], path: '/socket.io', }); diff --git a/src/GamePages/components/Canvas.js b/src/GamePages/components/Canvas.js index 9135c65..3eb178d 100644 --- a/src/GamePages/components/Canvas.js +++ b/src/GamePages/components/Canvas.js @@ -1,7 +1,7 @@ import React, { useRef, useEffect } from 'react'; import io from 'socket.io-client'; // import './styles/board.css'; - +require('dotenv').config(); export default function Canvas() { const canvasRef = useRef(null); const colorsRef = useRef(null); @@ -151,7 +151,7 @@ export default function Canvas() { drawLine(data.x0 * w, data.y0 * h, data.x1 * w, data.y1 * h, data.color); }; - socketRef.current = io.connect('http://localhost:4000', { + socketRef.current = io.connect(`${process.env.REACT_APP_API_SERVER}`, { transports: ['websocket', 'polling'], path: '/socket.io', }); diff --git a/src/GamePages/components/Canvas3.js b/src/GamePages/components/Canvas3.js index b7b1a24..dd474d4 100644 --- a/src/GamePages/components/Canvas3.js +++ b/src/GamePages/components/Canvas3.js @@ -8,6 +8,7 @@ import Crayon_Blue from '../../images/crayon_blue.png'; import Crayon_Green from '../../images/crayon_green.png'; import Crayon_Yellow from '../../images/crayon_yellow.png'; import io from 'socket.io-client'; +require('dotenv').config(); export default function Canvas3() { const canvasRef = useRef(null); @@ -121,7 +122,7 @@ export default function Canvas3() { drawLine(data.x0 * w, data.y0 * h, data.x1 * w, data.y1 * h, data.color); }; - socketRef.current = io.connect('http://localhost:4000', { + socketRef.current = io.connect(`${process.env.REACT_APP_API_SERVER}`, { transports: ['websocket', 'polling'], path: '/socket.io', }); diff --git a/src/GamePages/components/Chat.js b/src/GamePages/components/Chat.js index ac8a4e1..fa4c5b8 100644 --- a/src/GamePages/components/Chat.js +++ b/src/GamePages/components/Chat.js @@ -35,7 +35,7 @@ export default function Chat({ chat, onMessageSubmit, onTextChange, state }) {