diff --git a/goofy-client/angular.json b/goofy-client/angular.json index eb185113ff51be77ae29cbaf1ebb59ea1d8ecf5e..e09e52b2f51222a2effe8ede14c35e175210fc70 100644 --- a/goofy-client/angular.json +++ b/goofy-client/angular.json @@ -378,7 +378,8 @@ "serve": { "builder": "@angular-devkit/build-angular:dev-server", "options": { - "browserTarget": "goofy:build" + "browserTarget": "goofy:build", + "proxyConfig": "proxy.conf.mjs" }, "configurations": { "production": { diff --git a/goofy-client/libs/environment-shared/src/index.ts b/goofy-client/libs/environment-shared/src/index.ts index b36c303810ad33838d4eae5b1fa87fe5426ecf4c..f7eb1ed0c419f217608d6a6a155bfa0cd4c63e83 100644 --- a/goofy-client/libs/environment-shared/src/index.ts +++ b/goofy-client/libs/environment-shared/src/index.ts @@ -23,3 +23,4 @@ */ export * from './lib/environment.module'; export * from './lib/environment.service'; + diff --git a/goofy-client/libs/tech-shared/src/lib/interceptor/xhr.interceptor.spec.ts b/goofy-client/libs/tech-shared/src/lib/interceptor/xhr.interceptor.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..5b91bc43068843b7fcc84c5791146696c0a2557e --- /dev/null +++ b/goofy-client/libs/tech-shared/src/lib/interceptor/xhr.interceptor.spec.ts @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2022 Das Land Schleswig-Holstein vertreten durch den + * Ministerpräsidenten des Landes Schleswig-Holstein + * Staatskanzlei + * Abteilung Digitalisierung und zentrales IT-Management der Landesregierung + * + * Lizenziert unter der EUPL, Version 1.2 oder - sobald + * diese von der Europäischen Kommission genehmigt wurden - + * Folgeversionen der EUPL ("Lizenz"); + * Sie dürfen dieses Werk ausschließlich gemäß + * dieser Lizenz nutzen. + * Eine Kopie der Lizenz finden Sie hier: + * + * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 + * + * Sofern nicht durch anwendbare Rechtsvorschriften + * gefordert oder in schriftlicher Form vereinbart, wird + * die unter der Lizenz verbreitete Software "so wie sie + * ist", OHNE JEGLICHE GEWÄHRLEISTUNG ODER BEDINGUNGEN - + * ausdrücklich oder stillschweigend - verbreitet. + * Die sprachspezifischen Genehmigungen und Beschränkungen + * unter der Lizenz sind dem Lizenztext zu entnehmen. + */ +import { HttpRequest } from '@angular/common/http'; +import { faker } from '@faker-js/faker'; +import { HttpMethod } from '../tech.model'; +import { XhrInterceptor } from './xhr.interceptor'; + +describe('XhrInterceptor', () => { + let interceptor: XhrInterceptor; + + const url: string = faker.internet.url(); + + beforeEach(() => { + interceptor = new XhrInterceptor(); + }) + + it('should be created', () => { + expect(interceptor).toBeTruthy(); + }); + + describe('addHeader', () => { + + it('should add X-Requested-With header', () => { + const request: HttpRequest<unknown> = new HttpRequest(HttpMethod.GET, url); + + const result: HttpRequest<unknown> = interceptor.addHeader(request); + + expect(result.headers.get('X-Requested-With')).toEqual('XMLHttpRequest'); + }) + }) +}); \ No newline at end of file diff --git a/goofy-client/libs/tech-shared/src/lib/interceptor/xhr.interceptor.ts b/goofy-client/libs/tech-shared/src/lib/interceptor/xhr.interceptor.ts new file mode 100644 index 0000000000000000000000000000000000000000..6d606a89bdca4aa6290ea82f5ab04d44d864a326 --- /dev/null +++ b/goofy-client/libs/tech-shared/src/lib/interceptor/xhr.interceptor.ts @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2022 Das Land Schleswig-Holstein vertreten durch den + * Ministerpräsidenten des Landes Schleswig-Holstein + * Staatskanzlei + * Abteilung Digitalisierung und zentrales IT-Management der Landesregierung + * + * Lizenziert unter der EUPL, Version 1.2 oder - sobald + * diese von der Europäischen Kommission genehmigt wurden - + * Folgeversionen der EUPL ("Lizenz"); + * Sie dürfen dieses Werk ausschließlich gemäß + * dieser Lizenz nutzen. + * Eine Kopie der Lizenz finden Sie hier: + * + * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 + * + * Sofern nicht durch anwendbare Rechtsvorschriften + * gefordert oder in schriftlicher Form vereinbart, wird + * die unter der Lizenz verbreitete Software "so wie sie + * ist", OHNE JEGLICHE GEWÄHRLEISTUNG ODER BEDINGUNGEN - + * ausdrücklich oder stillschweigend - verbreitet. + * Die sprachspezifischen Genehmigungen und Beschränkungen + * unter der Lizenz sind dem Lizenztext zu entnehmen. + */ +import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { Observable } from 'rxjs'; + +@Injectable() +export class XhrInterceptor implements HttpInterceptor { + + intercept(req: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> { + return next.handle(this.addHeader(req)); + } + + addHeader(req: HttpRequest<unknown>): HttpRequest<unknown> { + return req.clone({ + headers: req.headers.set('X-Requested-With', 'XMLHttpRequest') + }); + } +} \ No newline at end of file diff --git a/goofy-client/libs/tech-shared/src/lib/tech-shared.module.ts b/goofy-client/libs/tech-shared/src/lib/tech-shared.module.ts index 155e6385f0d3e90db061b2684927ef1de77d0483..50efc0642f52bb3f1c92c2465e8de05525615ca1 100644 --- a/goofy-client/libs/tech-shared/src/lib/tech-shared.module.ts +++ b/goofy-client/libs/tech-shared/src/lib/tech-shared.module.ts @@ -26,6 +26,7 @@ import { HTTP_INTERCEPTORS } from '@angular/common/http'; import { Injector, NgModule } from '@angular/core'; import { HttpBinaryFileInterceptor } from './interceptor/http-binary-file.interceptor'; import { HttpXsrfInterceptor } from './interceptor/http-xsrf.interceptor'; +import { XhrInterceptor } from './interceptor/xhr.interceptor'; import { ConvertForDataTestPipe } from './pipe/convert-for-data-test.pipe'; import { EnumToLabelPipe } from './pipe/enum-to-label.pipe'; import { FileSizePipe } from './pipe/file-size.pipe'; @@ -67,6 +68,11 @@ import { ToTrafficLightPipe } from './pipe/to-traffic-light.pipe'; FileSizePipe, ], providers: [ + { + provide: HTTP_INTERCEPTORS, + useClass: XhrInterceptor, + multi: true, + }, { provide: HTTP_INTERCEPTORS, useClass: HttpXsrfInterceptor, diff --git a/goofy-client/libs/ui/src/lib/ui/ui.module.ts b/goofy-client/libs/ui/src/lib/ui/ui.module.ts index a69544f3de717ed42696da8a7815a6f6b227b6ee..9a37578f0a282c7909fd73fefb9bddbf7e5d1bb9 100644 --- a/goofy-client/libs/ui/src/lib/ui/ui.module.ts +++ b/goofy-client/libs/ui/src/lib/ui/ui.module.ts @@ -29,20 +29,20 @@ import { DateFnsAdapter, MatDateFnsModule } from '@angular/material-date-fns-adapter'; -import { MatLegacyAutocompleteModule as MatAutocompleteModule } from '@angular/material/legacy-autocomplete'; import { MatBadgeModule } from '@angular/material/badge'; -import { MatLegacyButtonModule as MatButtonModule } from '@angular/material/legacy-button'; -import { MatLegacyCheckboxModule as MatCheckboxModule } from '@angular/material/legacy-checkbox'; import { DateAdapter, MatRippleModule, MAT_DATE_LOCALE } from '@angular/material/core'; import { MatDatepickerModule } from '@angular/material/datepicker'; -import { MatLegacyDialogModule as MatDialogModule } from '@angular/material/legacy-dialog'; import { MatExpansionModule } from '@angular/material/expansion'; -import { MatLegacyFormFieldModule as MatFormFieldModule } from '@angular/material/legacy-form-field'; import { MatIconModule } from '@angular/material/icon'; +import { MatLegacyAutocompleteModule as MatAutocompleteModule } from '@angular/material/legacy-autocomplete'; +import { MatLegacyButtonModule as MatButtonModule } from '@angular/material/legacy-button'; +import { MatLegacyCheckboxModule as MatCheckboxModule } from '@angular/material/legacy-checkbox'; +import { MatLegacyDialogModule as MatDialogModule } from '@angular/material/legacy-dialog'; +import { MatLegacyFormFieldModule as MatFormFieldModule } from '@angular/material/legacy-form-field'; import { MatLegacyInputModule as MatInputModule } from '@angular/material/legacy-input'; import { MatLegacyListModule as MatListModule } from '@angular/material/legacy-list'; import { MatLegacyMenuModule as MatMenuModule } from '@angular/material/legacy-menu'; diff --git a/goofy-client/package.json b/goofy-client/package.json index 07cdf1fc534f9dd4e9b761320f568caf06207b94..841492de89be0aaf7cc9ba8551bbee9616413137 100644 --- a/goofy-client/package.json +++ b/goofy-client/package.json @@ -4,8 +4,8 @@ "license": "MIT", "scripts": { "postinstall": "node ./decorate-angular-cli.js && ngcc --properties es2020 browser module main --first-only --create-ivy-entry-points", - "start": "nx serve --port 4300 --disable-host-check --proxy-config proxy.conf.json --verbose", - "start-for-screenreader": "nx serve --host 192.168.178.20 --port 4300 --disable-host-check --proxy-config proxy.conf.json --verbose", + "start": "nx serve --port 4300 --disable-host-check --verbose", + "start-for-screenreader": "nx serve --host 192.168.178.20 --port 4300 --disable-host-check --verbose", "start:devbe": "nx serve --port 4300 --disable-host-check --proxy-config proxy.dev.conf.json --verbose", "build": "nx build", "test": "node ./node_modules/.bin/nx run-many --target=test --all --parallel --maxParallel 8 --runInBand", diff --git a/goofy-client/proxy.conf.json b/goofy-client/proxy.conf.mjs similarity index 66% rename from goofy-client/proxy.conf.json rename to goofy-client/proxy.conf.mjs index 4bc3d0b5262907841d1fcb13583bd2839e203860..c16495c509a13c80f13d7e9ad8a073b9f6ab0b07 100644 --- a/goofy-client/proxy.conf.json +++ b/goofy-client/proxy.conf.mjs @@ -1,5 +1,9 @@ -{ - "/api": { +export default [ + { + "context": [ + "/api", + "/sso" + ], "target": { "host": "localhost", "port": 8080, @@ -8,4 +12,4 @@ "secure": false, "logLevel": "debug" } -} \ No newline at end of file +]; \ No newline at end of file