Skip to content
Permalink
Browse files
Mock mode
  • Loading branch information
nerdic-coder committed Aug 18, 2020
1 parent f615e9a commit 2401f99a95e70a359e508340698c2aeeeeafd2de
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 18 deletions.
@@ -19,13 +19,8 @@
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"aot": true,
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.css"
],
"assets": ["src/favicon.ico", "src/assets"],
"styles": ["src/styles.css"],
"scripts": []
},
"configurations": {
@@ -56,6 +51,40 @@
"maximumError": "10kb"
}
]
},
"mock": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.mock.ts"
}
],
"assets": [
{
"glob": "**/*",
"input": "src/assets",
"output": "assets"
},
{
"glob": "**/*",
"input": "src/mock",
"output": "mock"
},
{
"glob": "**/*.svg",
"input": "node_modules/ionicons/dist/ionicons/svg",
"output": "./svg"
}
],
"optimization": false,
"outputHashing": "all",
"sourceMap": true,
"extractCss": true,
"namedChunks": false,
"aot": false,
"extractLicenses": false,
"vendorChunk": false,
"buildOptimizer": false
}
}
},
@@ -67,6 +96,9 @@
"configurations": {
"production": {
"browserTarget": "my-mock-app:build:production"
},
"mock": {
"browserTarget": "my-mock-app:build:mock"
}
}
},
@@ -83,13 +115,8 @@
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.spec.json",
"karmaConfig": "karma.conf.js",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.css"
],
"assets": ["src/favicon.ico", "src/assets"],
"styles": ["src/styles.css"],
"scripts": []
}
},
@@ -101,9 +128,7 @@
"tsconfig.spec.json",
"e2e/tsconfig.json"
],
"exclude": [
"**/node_modules/**"
]
"exclude": ["**/node_modules/**"]
}
},
"e2e": {
@@ -115,6 +140,9 @@
"configurations": {
"production": {
"devServerTarget": "my-mock-app:serve:production"
},
"mock": {
"devServerTarget": "my-mock-app:serve:mock"
}
}
}
@@ -125,4 +153,4 @@
"cli": {
"analytics": "6f610c9a-4265-4f50-aa61-422f75ad616b"
}
}
}
@@ -4,6 +4,7 @@
"scripts": {
"ng": "ng",
"start": "ng serve",
"mock": "ng serve --configuration mock",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
@@ -0,0 +1,27 @@
import { Injectable } from '@angular/core';
import {
HttpEvent,
HttpInterceptor,
HttpHandler,
HttpRequest,
} from '@angular/common/http';
import { Observable } from 'rxjs';
import { environment } from '../../environments/environment';

/** Pass untouched request through to the next request handler. */
@Injectable()
export class MockInterceptor implements HttpInterceptor {
intercept(
req: HttpRequest<any>,
next: HttpHandler
): Observable<HttpEvent<any>> {
if (!environment.mock) {
return next.handle(req);
} else {
const mockReq = req.clone({
method: 'GET',
});
return next.handle(mockReq);
}
}
}
@@ -0,0 +1,5 @@
export const environment = {
production: false,
mock: true,
endpoint: 'http://localhost:4200/mock/',
};
@@ -1,4 +1,5 @@
export const environment = {
production: true,
mock: false,
endpoint: 'https://api.punkapi.com/v2/',
};
@@ -4,6 +4,7 @@

export const environment = {
production: false,
mock: false,
endpoint: 'https://api.punkapi.com/v2/',
};

@@ -0,0 +1,27 @@
[
{
"id": 1,
"name": "Buzz",
"tagline": "A Real Bitter Experience."
},
{
"id": 2,
"name": "Trashy Blonde",
"tagline": "You Know You Shouldn't"
},
{
"id": 3,
"name": "Berliner Weisse With Yuzu - B-Sides",
"tagline": "Japanese Citrus Berliner Weisse."
},
{
"id": 4,
"name": "Pilsen Lager",
"tagline": "Unleash the Yeast Series."
},
{
"id": 5,
"name": "Avery Brown Dredge",
"tagline": "Bloggers' Imperial Pilsner."
}
]

0 comments on commit 2401f99

Please sign in to comment.