diff --git a/nginx.conf b/nginx.conf index e07a5d58..4a94bd6b 100644 --- a/nginx.conf +++ b/nginx.conf @@ -2,13 +2,18 @@ server { listen 80; server_name localhost; + location ~ ^/api/(me|token) { + proxy_pass http://auth-backend:8000; + proxy_http_version 1.1; + } + location /api/ { - proxy_pass http://data-backend:8000/api/; + proxy_pass http://data-backend:8000; proxy_http_version 1.1; } location /static/ { - proxy_pass http://data-backend:8000/static/; + proxy_pass http://data-backend:8000; proxy_http_version 1.1; } diff --git a/src/constants/env.ts b/src/constants/env.ts new file mode 100644 index 00000000..21fe878a --- /dev/null +++ b/src/constants/env.ts @@ -0,0 +1,3 @@ +export const ENV_LOCAL = 'local'; +export const ENV_TEST = 'test'; +export const ENV_PRODUCTION = 'production'; diff --git a/src/constants/index.ts b/src/constants/index.ts index e4496ffc..2b3e4aa3 100644 --- a/src/constants/index.ts +++ b/src/constants/index.ts @@ -1 +1,2 @@ export * from './errorCode'; +export * from './env'; diff --git a/src/main.ts b/src/main.ts index c3820dcb..be9af93d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -11,8 +11,6 @@ import './plugins/font-awesome'; const app = createApp(App); -const env = import.meta.env.VITE_APP_ENV; -console.log('env', env); app.use(router); app.use(store); app.use(ElementPlus); diff --git a/src/utils/baseUrl.ts b/src/utils/baseUrl.ts index d9cbbd3b..8930f83c 100644 --- a/src/utils/baseUrl.ts +++ b/src/utils/baseUrl.ts @@ -1,3 +1,4 @@ +import { ENV_LOCAL, ENV_TEST } from '@/constants'; import { getEnv } from './env'; /** @@ -6,9 +7,9 @@ import { getEnv } from './env'; */ export const getDataBaseUrl = () => { const env = getEnv(); - if (env === 'local') { + if (env === ENV_LOCAL) { return 'https://data.local.zhishuyun.com'; - } else if (env === 'test') { + } else if (env === ENV_TEST) { return 'https://data.test.zhishuyun.com'; } else { return 'https://data.zhishuyun.com'; @@ -17,9 +18,9 @@ export const getDataBaseUrl = () => { export const getAuthBaseUrl = () => { const env = getEnv(); - if (env === 'local') { + if (env === ENV_LOCAL) { return 'https://auth.test.zhishuyun.com'; - } else if (env === 'test') { + } else if (env === ENV_TEST) { return 'https://auth.test.zhishuyun.com'; } else { return 'https://auth.zhishuyun.com'; diff --git a/src/utils/env.ts b/src/utils/env.ts index 63eaaa34..46d0ce53 100644 --- a/src/utils/env.ts +++ b/src/utils/env.ts @@ -1,7 +1,19 @@ +import { ENV_LOCAL, ENV_PRODUCTION, ENV_TEST } from '@/constants'; + +const PATTERN_TEST_ENV = '.test.zhishuyun.com'; +const PATTERN_LOCAL_ENV = '.lcoal.zhishuyun.com'; + /** * Get env of App, return local, test, production * @returns */ export const getEnv = () => { - return import.meta.env.VITE_APP_ENV; + const host = window.location.host; + if (host.indexOf(PATTERN_LOCAL_ENV) > 0) { + return ENV_LOCAL; + } + if (host.indexOf(PATTERN_TEST_ENV) > 0) { + return ENV_TEST; + } + return ENV_PRODUCTION; };