Skip to content

Commit

Permalink
Fix: CORS settings fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
jjyyhh0208 committed Oct 24, 2024
1 parent 9435394 commit 5437505
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
9 changes: 5 additions & 4 deletions backend/worklog/worklog/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,12 @@
]

# CORS
CORS_ALLOW_ALL_ORIGINS = False
CORS_ALLOW_ALL_ORIGINS = True
CORS_ALLOWED_ORIGINS = [

'https://api.worklog.my',
'http://api.worklog.my',
]
# CORS_ALLOW_CREDENTIALS = True
CORS_ALLOW_CREDENTIALS = True
# CORS_ALLOW_HEADERS = '*'

# CSRF
Expand Down Expand Up @@ -143,7 +144,7 @@
]

MIDDLEWARE = [
# "corsheaders.middleware.CorsMiddleware",
"corsheaders.middleware.CorsMiddleware",
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import Header from './components/Header/Header';
import AuthRedirect from './components/Auth/AuthRedirect';
import ProtectedRoute from './components/Auth/ProtectedRoute';

//django에서 csrf 토큰을 쿠키에 포함에서 주기 때문에 어디서 이를 확인할지와 어떻게 보낼지 설정
axios.defaults.xsrfCookieName = 'csrftoken';
axios.defaults.xsrfHeaderName = 'X-CSRFToken';

Expand All @@ -61,6 +62,7 @@ function App() {
});
const [profileData, setProfileData] = useState(null);

//localStorage에 authToken이 있으면 true, 없으면 false
const isLoggedIn = () => {
return !!localStorage.getItem('authToken');
};
Expand All @@ -80,10 +82,12 @@ function App() {
'/friend-profile/:id',
];

//root url이면 항상 true 반환
if (location.pathname === '/') {
return true;
}

//위 리스트의 url에 현재 url이 존재하면 true 반환
return pathsWithHeader.some((path) => {
const regexPath = new RegExp('^' + path.replace(/:[^\s/]+/g, '([^/]+)') + '$');
return regexPath.test(location.pathname);
Expand Down
9 changes: 0 additions & 9 deletions frontend/src/pages/Main/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,8 @@ import 'react-responsive-carousel/lib/styles/carousel.min.css';
import typeData from '../../data/typeData.json';

function Main() {
const navigate = useNavigate();
const refs = useRef(typeData.types.map(() => React.createRef()));

const handleLoginClick = () => {
navigate('/login');
};

const handleSignUpClick = () => {
navigate('/signup/1');
};

const scrollToSection = (index) => {
const offset = 100;
const top = refs.current[index].current.getBoundingClientRect().top + window.pageYOffset - offset;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/utils/AdminService.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const AdminService = {
},

checkUserName: (userName) => {
return API.post('/profiles/auth/check-username/', { username: userName }) // Pass the username as an object
return API.post('accounts/check-username/', { username: userName }) // Pass the username as an object
.then((response) => {
return response.data; // Return response data for further use
})
Expand Down

0 comments on commit 5437505

Please sign in to comment.