Skip to content

Commit

Permalink
add: türkiyeli is forbidden using interceptor
Browse files Browse the repository at this point in the history
  • Loading branch information
4Furki4 committed Jul 20, 2023
1 parent 07da636 commit d5434da
Show file tree
Hide file tree
Showing 5 changed files with 191 additions and 0 deletions.
46 changes: 46 additions & 0 deletions nx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"tasksRunnerOptions": {
"default": {
"runner": "nx-cloud",
"options": {
"cacheableOperations": [
"build",
"test"
],
"accessToken": "ODQ2ZGViZDMtY2NmNi00YjFjLWE5YTctZmI0MzYzZWZhNDg2fHJlYWQtd3JpdGU="
}
}
},
"affected": {
"defaultBase": "main"
},
"namedInputs": {
"sharedGlobals": [],
"default": [
"{projectRoot}/**/*",
"sharedGlobals"
],
"production": [
"default",
"!{projectRoot}/tsconfig.spec.json",
"!{projectRoot}/**/*.spec.[jt]s"
]
},
"targetDefaults": {
"build": {
"dependsOn": [
"^build"
],
"inputs": [
"production",
"^production"
]
},
"test": {
"inputs": [
"default",
"^production"
]
}
}
}
101 changes: 101 additions & 0 deletions project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{
"$schema": "node_modules/nx/schemas/project-schema.json",
"name": "sozluk",
"projectType": "application",
"generators": {
"@schematics/angular:component": {
"style": "scss"
}
},
"sourceRoot": "src",
"prefix": "sozluk",
"targets": {
"build": {
"executor": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/sozluk",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": [
"zone.js"
],
"tsConfig": "tsconfig.app.json",
"inlineStyleLanguage": "scss",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.scss"
],
"scripts": []
},
"configurations": {
"production": {
"budgets": [
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "1mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "2kb",
"maximumError": "4kb"
}
],
"outputHashing": "all"
},
"development": {
"buildOptimizer": false,
"optimization": false,
"vendorChunk": true,
"extractLicenses": false,
"sourceMap": true,
"namedChunks": true
}
},
"defaultConfiguration": "production",
"outputs": [
"{options.outputPath}"
]
},
"serve": {
"executor": "@angular-devkit/build-angular:dev-server",
"configurations": {
"production": {
"browserTarget": "sozluk:build:production"
},
"development": {
"browserTarget": "sozluk:build:development"
}
},
"defaultConfiguration": "development"
},
"extract-i18n": {
"executor": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "sozluk:build"
}
},
"test": {
"executor": "@angular-devkit/build-angular:karma",
"options": {
"polyfills": [
"zone.js",
"zone.js/testing"
],
"tsConfig": "tsconfig.spec.json",
"inlineStyleLanguage": "scss",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.scss"
],
"scripts": []
}
}
}
}
6 changes: 6 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { MainModule } from './components/main/main.module';
import { HTTP_INTERCEPTORS, HttpClientModule } from '@angular/common/http';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { CachingInterceptor } from './services/interceptors/caching.interceptor';
import { ForbiddenInterceptor } from './services/interceptors/forbidden.interceptor';

@NgModule({
declarations: [
Expand All @@ -23,6 +24,11 @@ import { CachingInterceptor } from './services/interceptors/caching.interceptor'
provide: HTTP_INTERCEPTORS,
useClass: CachingInterceptor,
multi: true
},
{
provide: HTTP_INTERCEPTORS,
useClass: ForbiddenInterceptor,
multi: true
}
],
bootstrap: [AppComponent]
Expand Down
16 changes: 16 additions & 0 deletions src/app/services/interceptors/forbidden.interceptor.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';

import { ForbiddenInterceptor } from './forbidden.interceptor';

describe('ForbiddenInterceptor', () => {
beforeEach(() => TestBed.configureTestingModule({
providers: [
ForbiddenInterceptor
]
}));

it('should be created', () => {
const interceptor: ForbiddenInterceptor = TestBed.inject(ForbiddenInterceptor);
expect(interceptor).toBeTruthy();
});
});
22 changes: 22 additions & 0 deletions src/app/services/interceptors/forbidden.interceptor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Injectable } from '@angular/core';
import {
HttpRequest,
HttpHandler,
HttpEvent,
HttpInterceptor
} from '@angular/common/http';
import { Observable } from 'rxjs';
import { environment } from 'src/app/environments/environment';

@Injectable()
export class ForbiddenInterceptor implements HttpInterceptor {

constructor() {}

intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
if(request.url.includes('türkiyeli')) { // return 403 forbidden if the request url contains 'türkiyeli'
return next.handle(request.clone({ url: environment.apiUrl+'/gts?ara=türk'}))
}
return next.handle(request);
}
}

1 comment on commit d5434da

@vercel
Copy link

@vercel vercel bot commented on d5434da Jul 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.