From 877851c58710c805c6dccb1d47e1df1ca7355a86 Mon Sep 17 00:00:00 2001 From: BennieMeng Date: Wed, 29 May 2019 17:47:07 +0800 Subject: [PATCH] frontend: add base-url --- src/frontend/package.json | 4 ++-- .../src/app/shared/interceptor/auth-interceptor.ts | 13 +++++++++++-- src/frontend/src/base-url.ts | 8 ++++++++ 3 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 src/frontend/src/base-url.ts diff --git a/src/frontend/package.json b/src/frontend/package.json index d902bcbbc..acfa571fe 100644 --- a/src/frontend/package.json +++ b/src/frontend/package.json @@ -4,8 +4,8 @@ "license": "MIT", "scripts": { "ng": "ng", - "start": "ng serve --host 0.0.0.0 --disable-host-check --proxy-config proxy.config.js --configuration hmr", - "build": "node --max_old_space_size=4096 ./node_modules/@angular/cli/bin/ng build --aot --prod --build-optimizer --base-href \"/public/\"", + "start": "ng serve --host 0.0.0.0 --disable-host-check --configuration hmr", + "build": "node --max_old_space_size=6000 ./node_modules/@angular/cli/bin/ng build --aot --prod --build-optimizer", "test": "ng test", "lint": "ng lint", "e2e": "ng e2e" diff --git a/src/frontend/src/app/shared/interceptor/auth-interceptor.ts b/src/frontend/src/app/shared/interceptor/auth-interceptor.ts index b59865f49..1bee1cab1 100644 --- a/src/frontend/src/app/shared/interceptor/auth-interceptor.ts +++ b/src/frontend/src/app/shared/interceptor/auth-interceptor.ts @@ -4,14 +4,23 @@ import { from } from 'rxjs'; import { HttpEvent, HttpHandler, HttpHeaders, HttpInterceptor, HttpRequest } from '@angular/common/http'; import 'rxjs/add/observable/fromPromise'; import { LoginTokenKey } from '../shared.const'; - +import { resolve } from 'url'; +import { DEV_URL, MASTER_URL } from '../../../base-url'; @Injectable() export class AuthInterceptor implements HttpInterceptor { + baseUrl = 'http://test.qihoo.cloud'; constructor() { } intercept(request: HttpRequest, next: HttpHandler): Observable> { - return from(this.handleAccess(request, next)); + const apiReq = request.clone({ + url: resolve(request.url.indexOf('assets/') > -1 + ? '/' + : process.env.NODE_ENV === 'development' + ? DEV_URL + : MASTER_URL, request.url) + }); + return from(this.handleAccess(apiReq, next)); } private async handleAccess(request: HttpRequest, next: HttpHandler): diff --git a/src/frontend/src/base-url.ts b/src/frontend/src/base-url.ts new file mode 100644 index 000000000..1e0cf0616 --- /dev/null +++ b/src/frontend/src/base-url.ts @@ -0,0 +1,8 @@ +const DEV_URL = 'http://10.16.111.156:8080'; +// const DEV_URL = 'http://www.test.qihoo.cloud'; +const MASTER_URL = 'https://www.qihoo.cloud'; + +export { + DEV_URL, + MASTER_URL +};