동적 API URL 설정
This commit is contained in:
parent
2d6b0fc7ce
commit
a03db24ab9
|
|
@ -29,7 +29,7 @@ app.use(express.urlencoded({ extended: true, limit: "10mb" }));
|
||||||
// CORS 설정
|
// CORS 설정
|
||||||
app.use(
|
app.use(
|
||||||
cors({
|
cors({
|
||||||
origin: config.cors.origin.split(',').map(url => url.trim()),
|
origin: config.cors.origin.split(",").map((url) => url.trim()),
|
||||||
credentials: true,
|
credentials: true,
|
||||||
methods: ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"],
|
methods: ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"],
|
||||||
allowedHeaders: ["Content-Type", "Authorization", "X-Requested-With"],
|
allowedHeaders: ["Content-Type", "Authorization", "X-Requested-With"],
|
||||||
|
|
@ -84,11 +84,13 @@ app.use(errorHandler);
|
||||||
|
|
||||||
// 서버 시작
|
// 서버 시작
|
||||||
const PORT = config.port;
|
const PORT = config.port;
|
||||||
|
const HOST = config.host;
|
||||||
|
|
||||||
app.listen(PORT, () => {
|
app.listen(PORT, HOST, () => {
|
||||||
logger.info(`🚀 Server is running on port ${PORT}`);
|
logger.info(`🚀 Server is running on ${HOST}:${PORT}`);
|
||||||
logger.info(`📊 Environment: ${config.nodeEnv}`);
|
logger.info(`📊 Environment: ${config.nodeEnv}`);
|
||||||
logger.info(`🔗 Health check: http://localhost:${PORT}/health`);
|
logger.info(`🔗 Health check: http://${HOST}:${PORT}/health`);
|
||||||
|
logger.info(`🌐 External access: http://39.117.244.52:${PORT}/health`);
|
||||||
});
|
});
|
||||||
|
|
||||||
export default app;
|
export default app;
|
||||||
|
|
|
||||||
|
|
@ -2,21 +2,21 @@ import axios, { AxiosResponse, AxiosError } from "axios";
|
||||||
|
|
||||||
// API 기본 URL 동적 설정 (클라이언트 사이드에서 현재 도메인 기반으로 결정)
|
// API 기본 URL 동적 설정 (클라이언트 사이드에서 현재 도메인 기반으로 결정)
|
||||||
const getApiBaseUrl = (): string => {
|
const getApiBaseUrl = (): string => {
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== "undefined") {
|
||||||
const currentHost = window.location.hostname;
|
const currentHost = window.location.hostname;
|
||||||
const currentPort = window.location.port;
|
const currentPort = window.location.port;
|
||||||
|
|
||||||
// 외부 IP로 접근한 경우
|
// 외부 IP로 접근한 경우
|
||||||
if (currentHost === '39.117.244.52') {
|
if (currentHost === "39.117.244.52") {
|
||||||
return 'http://39.117.244.52:8080/api';
|
return "http://39.117.244.52:8080/api";
|
||||||
}
|
}
|
||||||
// 내부 IP로 접근한 경우
|
// 내부 IP로 접근한 경우
|
||||||
else if (currentHost === '192.168.0.70') {
|
else if (currentHost === "192.168.0.70") {
|
||||||
return 'http://192.168.0.70:8080/api';
|
return "http://192.168.0.70:8080/api";
|
||||||
}
|
}
|
||||||
// localhost로 접근한 경우
|
// localhost로 접근한 경우
|
||||||
else if (currentHost === 'localhost' || currentHost === '127.0.0.1') {
|
else if (currentHost === "localhost" || currentHost === "127.0.0.1") {
|
||||||
return 'http://localhost:8080/api';
|
return "http://localhost:8080/api";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue