Skip to content

Commit 3257522

Browse files
committed
build: Update Environment files so that server can supply the production mode. #22
1 parent ca60c65 commit 3257522

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

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"

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)