Skip to content

Commit

Permalink
fix: db관련 코드 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
sooieese00 committed Sep 10, 2024
1 parent 1a0601f commit 6eb838f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
3 changes: 3 additions & 0 deletions configs/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@ module.exports = {
username: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
port: process.env.DB_PORT,
host: process.env.DB_HOST,
dialect: 'mysql'
},
test: {
username: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
port: process.env.DB_PORT,
host: process.env.DB_HOST,
dialect: 'mysql'
},
production: {
username: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
port: process.env.DB_PORT,
host: process.env.DB_HOST,
dialect: 'mysql'
}
Expand Down
16 changes: 11 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
const express = require('express');
const mysql = require('mysql2/promise');
const cookieParser = require('cookie-parser');
const session = require('express-session');
const passport = require('passport');

const app = express();

require('dotenv').config();
const port = process.env.PORT;

app.use(express.json());

// db 관련 설정
const db = require('./models');
db.sequelize
.sync({force: false})
.then(() => {
console.log('DB 연결 성공');
})
.catch(err => console.log(err));

// 쿠키, 세션 설정
app.use(cookieParser(process.env.COOKIE_SECRET));
app.use(session({
secret: process.env.COOKIE_SECRET,
resave: false,
saveUninitialized: false,
cookie: {
httpOnly: true,
secure: false,
},
}));

// 로그인을 위한 Passport 세팅
Expand Down
2 changes: 1 addition & 1 deletion models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Sequelize = require('sequelize');
const User = require('./user');

const env = process.env.NODE_ENV || 'development';
const config = require('../config/config')[env];
const config = require('../configs/config')[env];

const sequelize = new Sequelize(config.database, config.username, config.password, config);

Expand Down

0 comments on commit 6eb838f

Please sign in to comment.