-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: 🚑 Fix proxies on production (#38)
* fix: 🚑 Fix proxies on production
- Loading branch information
Showing
9 changed files
with
71 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './lib/shared-interceptors.module'; | ||
export * from './lib/spotify-token.interceptor'; | ||
export * from './lib/proxy.interceptor'; |
16 changes: 16 additions & 0 deletions
16
libs/shared/interceptors/src/lib/proxy.interceptor.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { ProxyInterceptor } from './proxy.interceptor'; | ||
|
||
describe('ProxyInterceptor', () => { | ||
beforeEach(() => | ||
TestBed.configureTestingModule({ | ||
providers: [ProxyInterceptor], | ||
}) | ||
); | ||
|
||
it('should be created', () => { | ||
const interceptor: ProxyInterceptor = TestBed.inject(ProxyInterceptor); | ||
expect(interceptor).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { | ||
HttpRequest, | ||
HttpHandler, | ||
HttpEvent, | ||
HttpInterceptor, | ||
} from '@angular/common/http'; | ||
import { Observable } from 'rxjs'; | ||
|
||
@Injectable() | ||
export class ProxyInterceptor implements HttpInterceptor { | ||
readonly proxies = ['minilyrics', 'minilyrics-proxy']; | ||
readonly proxiesRegex = this.proxies.map( | ||
(proxy) => new RegExp('.{2}/' + proxy) | ||
); | ||
|
||
intercept( | ||
request: HttpRequest<unknown>, | ||
next: HttpHandler | ||
): Observable<HttpEvent<unknown>> { | ||
if (this.proxiesRegex.some((proxyRegex) => proxyRegex.test(request.url))) { | ||
const dupReq = request.clone({ url: request.url.slice(3) }); | ||
return next.handle(dupReq); | ||
} | ||
return next.handle(request); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters