Skip to content

Commit

Permalink
add: forbidden words added for inputs
Browse files Browse the repository at this point in the history
interceptor is improved using url.replace function.
  • Loading branch information
4Furki4 committed Jul 20, 2023
1 parent d5434da commit 27d4285
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ const shadowAnimation = trigger('animateShadow', [
animations: [shadowAnimation]
})
export class SearchInputComponent {
forbiddenWords : {
[key: string]: string
} = {
'türkiyeli': 'türk',
}
constructor(private route: Router) {

}
@ViewChild("searchForm") searchForm!: NgForm;
@ViewChild("inputEl") wordInputEl!: HTMLInputElement;
Expand All @@ -34,6 +38,9 @@ export class SearchInputComponent {
onSubmit() {
if (this.isInputValueValid) {
let cleansedWord = this.wordInput.toLowerCase().trim()
if (this.forbiddenWords[cleansedWord]) {
cleansedWord = this.forbiddenWords[cleansedWord]
}
this.route.navigate([`${cleansedWord}`])
return true
}
Expand Down
5 changes: 3 additions & 2 deletions src/app/services/interceptors/forbidden.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ 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'}))
if(request.url.includes('türkiyeli')) { // redirect to türk
request = request.clone({
url: request.url.replace('türkiyeli', 'türk')})
}
return next.handle(request);
}
Expand Down

1 comment on commit 27d4285

@vercel
Copy link

@vercel vercel bot commented on 27d4285 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.