Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid bundling the mock interceptor in prod env #448

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NgModule, APP_INITIALIZER } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouterModule, Routes } from '@angular/router';
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { HttpClientModule } from '@angular/common/http';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { environment } from '../environments/environment';
Expand Down Expand Up @@ -29,11 +29,6 @@ import { AlertService } from './services/alert.service';
import { NavigationService } from './services/navigation.service';
import { HeaderComponent } from './components/header/header.component';

import { HttpRequestInterceptor } from './interceptors/request.interceptor';
import { HttpMockRequestInterceptor } from './interceptors/mock.interceptor';

export const isMock = environment.mock;

const appRoutes: Routes = [
{ path: 'run-test/:domain', component: DomainComponent },
{ path: 'run-test', component: DomainComponent },
Expand Down Expand Up @@ -82,19 +77,15 @@ const appRoutes: Routes = [
DnsCheckService,
AlertService,
NavigationService,
{
provide: HTTP_INTERCEPTORS,
useClass: isMock ? HttpMockRequestInterceptor : HttpRequestInterceptor,
multi: true
},
{
provide: APP_INITIALIZER,
useFactory: (appService: AppService) => {
return () => appService.loadConfig()
},
multi: true,
deps: [AppService]
}
},
...environment.extraProvider,
],
bootstrap: [AppComponent]
})
Expand Down
14 changes: 0 additions & 14 deletions src/app/interceptors/request.interceptor.ts

This file was deleted.

3 changes: 2 additions & 1 deletion src/environments/environment.prod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export const environment = {
...common,
production: true,
apiEndpoint: '/api',
mock: false
mock: false,
extraProvider: [],
};
9 changes: 9 additions & 0 deletions src/environments/environment.tests.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { common } from "./common";
import { HTTP_INTERCEPTORS } from "@angular/common/http";
import { HttpMockRequestInterceptor } from "../app/interceptors/mock.interceptor";

export const environment = {
...common,
Expand All @@ -8,4 +10,11 @@ export const environment = {
// Use a non existent file to always load the config from the environment file
configUrl: 'assets/app.config.non-existent.json',
pollingInterval: 0.1 * 1000,
extraProvider: [
{
provide: HTTP_INTERCEPTORS,
useClass: HttpMockRequestInterceptor,
multi: true
}
]
};
11 changes: 10 additions & 1 deletion src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@
// `ng build --env=prod` then `environment.prod.ts` will be used instead.
// The list of which env maps to which file can be found in `.angular-cli.json`.
import { common } from "./common";
import { HttpMockRequestInterceptor } from "../app/interceptors/mock.interceptor";
import { HTTP_INTERCEPTORS } from "@angular/common/http";

export const environment = {
...common,
production: false,
apiEndpoint: '/api',
mock: true
mock: true,
extraProvider: [
{
provide: HTTP_INTERCEPTORS,
useClass: HttpMockRequestInterceptor,
multi: true
}
]
};