Skip to content
Snippets Groups Projects
Commit 1b9c7336 authored by tpgus2603's avatar tpgus2603
Browse files

jwt기반 로그인인증

parent e0ea0904
No related branches found
No related tags found
1 merge request!42[#25] 배포코드 master브랜치로 이동
......@@ -17,33 +17,14 @@ const app = express();
app.use(morgan('dev')); //로깅용
// CORS 설정
const corsOptions = {
origin: (origin, callback) => {
console.log('CORS Origin:', origin); // 디버깅용 로그
const allowedOrigins = [
'http://localhost:3000', // 로컬 개발 환경
'http://ec2-43-203-68-83.ap-northeast-2.compute.amazonaws.com', // EC2 백엔드
];
if (!origin) return callback(null, true); // origin이 없으면 허용 (e.g., Postman)
if (allowedOrigins.includes(origin)) {
return callback(null, true);
}
console.log('CORS origin rejected:', origin); // 차단된 origin 로그
return callback(new Error('Not allowed by CORS'));
},
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
allowedHeaders: ['Content-Type', 'Authorization'],
credentials: true, // 쿠키 허용
};
// CORS 미들웨어 적용
app.use(cors(corsOptions));
// Preflight 요청 처리
app.options('*', cors(corsOptions));
app.use(
cors({
origin: process.env.FRONTEND_URL,
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
allowedHeaders: ['Content-Type', 'Authorization'],
credentials: true,
})
);
//
app.use(
session({
......@@ -74,7 +55,7 @@ app.use(flash());
console.log('MongoDB URI:', process.env.MONGO_URI);
//라우터 등록
const authRoutes = require('./routes/auth');
app.use('/api/auth',authRoutes);
app.use('/auth', authRoutes);
const scheduleRoutes = require('./routes/schedule');
app.use('/api/schedule', scheduleRoutes);
......@@ -111,4 +92,4 @@ const PORT = process.env.PORT || 3000;
console.error('❌ 서버 시작 중 오류 발생:', error);
process.exit(1);
}
})();
})();
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment