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

bugfix: 서버실행코드 오류해결(#21)

parent 33346a75
No related branches found
No related tags found
1 merge request!31Develop
// app.js
require('dotenv').config();
const express = require('express');
const session = require('express-session');
const passport = require('./passport');
......@@ -10,7 +9,7 @@ const { initScheduleCleaner } = require('./utils/scheduler');
const connectMongoDB = require('./config/mongoose'); // MongoDB 연결
const { sequelize } = require('./config/sequelize'); // Sequelize 연결
const cors = require('cors');
const syncRdb = require('./sync'); // Import the syncDatabase function
const app = express();
// CORS 설정
......@@ -43,7 +42,7 @@ app.use(passport.session());
app.use(flash());
console.log('MongoDB URI:', process.env.MONGO_URI);
//라우터 등록
const authRoutes = require('./routes/auth');
app.use('/auth', authRoutes);
......@@ -74,10 +73,9 @@ const PORT = process.env.PORT || 3000;
// MongoDB 연결
await connectMongoDB();
//console.log('✅ MongoDB 연결 성공');
console.log('MongoDB URI:', process.env.MONGO_URI);
// MySQL 연결 확인
await sequelize.authenticate();
//console.log('✅ MySQL 연결 성공');
await syncRdb();
// 서버 시작
app.listen(PORT, () => {
......
......@@ -4,7 +4,7 @@ const mongoose = require('mongoose');
const connectMongoDB = async () => {
try {
await mongoose.connect(process.env.MONGODB_URI, {
await mongoose.connect(process.env.MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
......
// sync.js
require('dotenv').config(); // 환경 변수 로드
//require('dotenv').config(); // 환경 변수 로드
const sequelize = require('./config/sequelize');
const model=require('./models'); // 모델들을 가져옴 (사이드 이펙트로 모델들이 등록됨)
async function syncDatabase() {
async function syncRdb() {
try {
// 데이터베이스 연결 테스트
await sequelize.authenticate();
console.log('데이터베이스 연결 성공.');
console.log('Rdb데이터베이스 연결 성공.');
// 모든 모델 동기화
await sequelize.sync({ force: true });
......@@ -17,10 +17,12 @@ async function syncDatabase() {
// 연결 종료
await sequelize.close();
console.log('데이터베이스 연결이 종료되었습니다.');
console.log('Rdb데이터베이스 연결이 종료되었습니다.');
} catch (error) {
console.error('데이터베이스 연결 실패:', error);
console.error('Rdb데이터베이스 연결 실패:', error);
}
}
syncDatabase();
module.exports = syncRdb;
\ 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