Skip to content

Commit a95c263

Browse files
committed
On master: production 환경변수 변경 내역
2 parents fe3db1b + 5ffa3ae commit a95c263

File tree

5 files changed

+39
-11
lines changed

5 files changed

+39
-11
lines changed

client/app/src/apis/instance.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
const { REACT_APP_HOST_ADDRESS, REACT_APP_SERVER_PORT } = process.env;
1+
const {
2+
REACT_APP_NODE_ENV, //
3+
REACT_APP_SERVER_HOST_ADDRESS, //
4+
REACT_APP_SERVER_PORT, //
5+
} = process.env;
26

37
export class HTTP {
48
private domain: string = "";
@@ -43,7 +47,11 @@ export class HTTP {
4347
}
4448

4549
const instance = new HTTP(
46-
`http://${REACT_APP_HOST_ADDRESS}:${REACT_APP_SERVER_PORT}`
50+
`http://${
51+
REACT_APP_NODE_ENV === "production"
52+
? REACT_APP_SERVER_HOST_ADDRESS
53+
: "localhost"
54+
}:${REACT_APP_SERVER_PORT}`
4755
);
4856

4957
export default instance;

config/.client.env

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
# If you want to deploy the production, put the "production".
2+
REACT_APP_NODE_ENV="development"
3+
14
# Client port number to open this react-app.
2-
PORT=80
5+
PORT=3000
36

47
# Enter the same value as the PORT environment variable written in .server.env.
58
REACT_APP_SERVER_PORT=8000
69

710
# Put the IP or host address of the computer you are using.
8-
REACT_APP_HOST_ADDRESS="52.78.64.144"
11+
# The REACT_APP_SERVER_HOST_ADDRESS below only works when REACT_APP_NODE_ENV is "production", otherwise it works as "localhost".
12+
REACT_APP_SERVER_HOST_ADDRESS="localhost"

config/.server.env

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
# If you want to deploy the production, put the "production".
2+
NODE_ENV="development"
3+
14
# NodeJS
25
PORT=8000
3-
HOST_ADDRESS="52.78.64.144" # Put the IP or host address of the computer you are using.
46

5-
# for accessing from Nodejs to MySQL
7+
# Put the IP or host address of the computer you are using.
8+
# The HOST_ADDRESS below only works when NODE_ENV is "production", otherwise it works as "localhost".
9+
HOST_ADDRESS="localhost"
10+
11+
# For accessing from Nodejs to MySQL
612
DB_HOST="db"
713
DB_USER="root"
814
DB_PSWORD="password"

scripts/start-all.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
# Print message on console.
2+
echo "[info] Starting server and client..."
3+
4+
# OS variable
15
CHECK_OS="`uname -s`"
26

7+
# Check OS and then RUN the services
38
if [[ ${CHECK_OS} = "Darwin"* ]]; then
49
npm run build --prefix ./server/app && docker-compose -f ./server/docker-compose.yml --env-file ./config/.server.env up -d && npm run start:client
510
elif [[ "$CHECK_OS" = "Linux"* ]]; then
@@ -11,3 +16,6 @@ elif [[ ${CHECK_OS} = "MINGW64"* ]]; then
1116
elif [[ ${CHECK_OS} = "CYGWIN"* ]]; then
1217
npm run start:windows
1318
fi
19+
20+
# Print message on console.
21+
echo "[info] Now enjoy the your dev-portfolio web!!"

server/app/main.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ dotenv.config({ path: '../../config/.server.env' });
99

1010
const app = express();
1111
const PORT = process.env.PORT || 8000;
12-
const HOST_ADDRESS = process.env.HOST_ADDRESS || 'localhost'
12+
const HOST_ADDRESS =
13+
process.env.NODE_ENV === 'production'
14+
? process.env.HOST_ADDRESS || 'localhost'
15+
: 'localhost';
1316

1417
const swaggerSpec = YAML.load(path.join(__dirname, './swagger.yaml'));
15-
const portInjectedSwaggerSpec = JSON.stringify(swaggerSpec).replace(
16-
'{PORT}',
17-
PORT.toString()
18-
).replace('{HOST_ADDRESS}', HOST_ADDRESS);
18+
const portInjectedSwaggerSpec = JSON.stringify(swaggerSpec)
19+
.replace('{PORT}', PORT.toString())
20+
.replace('{HOST_ADDRESS}', HOST_ADDRESS);
1921

2022
import visitor from './src/apis/visitor';
2123

0 commit comments

Comments
 (0)