Skip to content
This repository was archived by the owner on Jul 10, 2019. It is now read-only.

Commit 9b23921

Browse files
committed
feat(env): add internalEndpointUrl and externalEndpointUrl
1 parent 3ab57db commit 9b23921

File tree

8 files changed

+43
-29
lines changed

8 files changed

+43
-29
lines changed

nuxt.config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ module.exports = {
1010
srcDir: 'src/',
1111

1212
env: {
13-
NODE_ENV: process.env.NODE_ENV
13+
NODE_ENV: process.env.NODE_ENV,
14+
BUILD_ENV: process.env.BUILD_ENV,
15+
envName: process.env.envName,
16+
internalEndpointUrl: process.env.internalEndpointUrl,
17+
externalEndpointUrl: process.env.externalEndpointUrl
1418
},
1519

1620
// https://qiita.com/toaru/items/0690a9110c94052bb479

src/common/constants/api.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
import Env from '@/common/env/'
22

3-
const getBffUrl = (path: string): string => [Env.url, path].join('')
3+
/**
4+
* BFF(バックエンドフォーフロントエンド)用の URL を作成する
5+
* @param path
6+
*/
7+
const getBffUrl = (path: string): string => {
8+
let url: string
9+
if (process.server) {
10+
url = [Env.internalEndpointUrl, path].join('')
11+
} else {
12+
url = [Env.externalEndpointUrl, path].join('')
13+
}
14+
return url
15+
}
416

517
/** API のエンドポイント */
618
export const API_ENDPOINT = {

src/common/env/env.dev.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/common/env/env.local.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const Env = {
2+
envName: 'local',
3+
internalEndpointUrl: 'http://localhost:5000',
4+
externalEndpointUrl: 'http://localhost:5000'
5+
}
6+
7+
export default Env

src/common/env/env.prod.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/common/env/env.stg.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/common/env/index.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1-
import EnvDev from './env.dev'
2-
import EnvStg from './env.stg'
3-
import EnvProd from './env.prod'
1+
import EnvLocal from './env.local'
42
import { IEnv } from '@/interface/IEnv'
53

64
console.log('process.env.NODE_ENV: ', process.env.NODE_ENV)
5+
console.log('process.env.BUILD_ENV: ', process.env.BUILD_ENV)
76

87
let Env: IEnv
9-
if (process.env.NODE_ENV === 'production') {
10-
Env = EnvProd
11-
} else if (process.env.NODE_ENV === 'staging') {
12-
Env = EnvStg
8+
if (process.env.BUILD_ENV === 'docker') {
9+
/** docker のビルド環境の環境変数から値を取ってくる */
10+
Env = {
11+
envName: process.env.envName,
12+
internalEndpointUrl: process.env.internalEndpointUrl,
13+
externalEndpointUrl: process.env.externalEndpointUrl
14+
} as IEnv
1315
} else {
14-
Env = EnvDev
16+
/** docker でビルドされていない場合は、 .env.local から値を取ってくる */
17+
Env = EnvLocal
1518
}
1619

20+
console.log('Env:', Env)
21+
1722
export default Env

src/interface/IEnv.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
* Env インターフェイス
33
*/
44
export interface IEnv {
5+
/** 環境名 */
56
envName: string
6-
url: string
7+
/** 内部向けエンドポイント URL */
8+
internalEndpointUrl: string
9+
/** 外部向けエンドポイント URL */
10+
externalEndpointUrl: string
711
}

0 commit comments

Comments
 (0)