auto commit
This commit is contained in:
parent
ea9fec95fd
commit
1fe981702a
@ -10,34 +10,48 @@ const registerRoutes = require("./routes");
|
|||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
// Middleware
|
// Middleware 설정
|
||||||
app.use(cors(config.cors));
|
app.use(cors(config.cors));
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
app.use(express.urlencoded({ extended: true }));
|
app.use(express.urlencoded({ extended: true }));
|
||||||
app.use(requestLogger);
|
app.use(requestLogger);
|
||||||
|
|
||||||
// Register all routes
|
// 라우트 등록
|
||||||
registerRoutes(app);
|
registerRoutes(app);
|
||||||
|
|
||||||
// Error handling
|
// 에러 핸들링
|
||||||
app.use(errorHandler);
|
app.use(errorHandler);
|
||||||
|
|
||||||
// Database initialization and server start
|
const waitForDatabase = async (retries = 5, interval = 2000) => {
|
||||||
const initializeServer = async () => {
|
for (let i = 0; i < retries; i++) {
|
||||||
try {
|
try {
|
||||||
await sequelize.authenticate();
|
await sequelize.authenticate();
|
||||||
logger.info("Database connection established successfully.");
|
logger.info("Database connection established successfully.");
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
logger.warn(`Database connection attempt ${i + 1} failed:`, error);
|
||||||
|
if (i < retries - 1) {
|
||||||
|
logger.info(`Retrying in ${interval / 1000} seconds...`);
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, interval));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new Error("Could not connect to database after multiple attempts");
|
||||||
|
};
|
||||||
|
|
||||||
// Sync database (in development only)
|
const initializeServer = async () => {
|
||||||
|
try {
|
||||||
|
// 데이터베이스 연결 대기
|
||||||
|
await waitForDatabase();
|
||||||
|
|
||||||
|
// 개발 환경에서만 데이터베이스 동기화
|
||||||
if (process.env.NODE_ENV !== "production") {
|
if (process.env.NODE_ENV !== "production") {
|
||||||
// force: true 옵션을 사용하여 테이블을 재생성
|
|
||||||
await sequelize.sync({ force: true });
|
await sequelize.sync({ force: true });
|
||||||
logger.info("Database synchronized.");
|
logger.info("Database synchronized.");
|
||||||
|
|
||||||
// 초기 데이터 생성
|
|
||||||
await require("./utils/createInitialAdmin")();
|
await require("./utils/createInitialAdmin")();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 서버 시작
|
||||||
const port = config.port;
|
const port = config.port;
|
||||||
app.listen(port, () => {
|
app.listen(port, () => {
|
||||||
logger.info(`Server is running on port ${port}`);
|
logger.info(`Server is running on port ${port}`);
|
||||||
|
@ -14,6 +14,16 @@ module.exports = {
|
|||||||
database: process.env.POSTGRES_DB,
|
database: process.env.POSTGRES_DB,
|
||||||
dialect: "postgres",
|
dialect: "postgres",
|
||||||
logging: true,
|
logging: true,
|
||||||
|
pool: {
|
||||||
|
max: 5,
|
||||||
|
min: 0,
|
||||||
|
acquire: 30000,
|
||||||
|
idle: 10000,
|
||||||
|
},
|
||||||
|
retry: {
|
||||||
|
max: 5,
|
||||||
|
timeout: 3000,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
jwt: {
|
jwt: {
|
||||||
secret: process.env.JWT_SECRET,
|
secret: process.env.JWT_SECRET,
|
||||||
@ -32,12 +42,22 @@ module.exports = {
|
|||||||
port: process.env.PORT || 3001,
|
port: process.env.PORT || 3001,
|
||||||
database: {
|
database: {
|
||||||
host: process.env.POSTGRES_HOST,
|
host: process.env.POSTGRES_HOST,
|
||||||
port: parseInt(process.env.POSTGRES_PORT),
|
port: parseInt(process.env.POSTGRES_PORT) || 5432,
|
||||||
username: process.env.POSTGRES_USER,
|
username: process.env.POSTGRES_USER,
|
||||||
password: process.env.POSTGRES_PASSWORD,
|
password: process.env.POSTGRES_PASSWORD,
|
||||||
database: process.env.POSTGRES_DB,
|
database: process.env.POSTGRES_DB,
|
||||||
dialect: "postgres",
|
dialect: "postgres",
|
||||||
logging: false,
|
logging: true,
|
||||||
|
pool: {
|
||||||
|
max: 5,
|
||||||
|
min: 0,
|
||||||
|
acquire: 30000,
|
||||||
|
idle: 10000,
|
||||||
|
},
|
||||||
|
retry: {
|
||||||
|
max: 5,
|
||||||
|
timeout: 3000,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
jwt: {
|
jwt: {
|
||||||
secret: process.env.JWT_SECRET,
|
secret: process.env.JWT_SECRET,
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
# fems-postgres/pg_hba.conf
|
# fems-postgres/pg_hba.conf
|
||||||
# TYPE DATABASE USER ADDRESS METHOD
|
# TYPE DATABASE USER ADDRESS METHOD
|
||||||
# "local" is for Unix domain socket connections only
|
# "local" is for Unix domain socket connections only
|
||||||
|
# TYPE DATABASE USER ADDRESS METHOD
|
||||||
local all all scram-sha-256
|
local all all scram-sha-256
|
||||||
# IPv4 local connections:
|
|
||||||
host all all 127.0.0.1/32 scram-sha-256
|
host all all 127.0.0.1/32 scram-sha-256
|
||||||
# IPv6 local connections:
|
|
||||||
host all all ::1/128 scram-sha-256
|
host all all ::1/128 scram-sha-256
|
||||||
# Allow connections from Docker network
|
|
||||||
host all all 0.0.0.0/0 scram-sha-256
|
host all all 0.0.0.0/0 scram-sha-256
|
||||||
|
host all all 172.16.0.0/12 scram-sha-256
|
||||||
|
host all all 192.168.0.0/16 scram-sha-256
|
Loading…
Reference in New Issue
Block a user