Compare commits

..

2 Commits

Author SHA1 Message Date
e51e2701b3 try to fix the CORS problems vol. 1 2025-01-14 11:20:33 +01:00
ada610d01f generalize the urls 2025-01-14 11:19:50 +01:00
5 changed files with 13 additions and 4 deletions

3
.env
View File

@@ -1 +1,2 @@
VITE_SIMPLE_REST_URL=http://localhost:8081/core/api/admin VITE_AUTH_URL=http://localhost:8080
VITE_GATEWAY_REST_URL=http://localhost:8081/core/api/admin

View File

@@ -8,7 +8,7 @@ export const authProvider: AuthProvider = {
try { try {
response = await fetch( response = await fetch(
new Request("http://localhost:8080/atsp-idp/token", { new Request(`${import.meta.env.VITE_AUTH_URL}/atsp-idp/token`, {
method: "POST", method: "POST",
credentials: "include", credentials: "include",
body: new URLSearchParams({ body: new URLSearchParams({

View File

@@ -2,7 +2,7 @@ import { useQueryEngine } from './hooks';
export const dataProviderExtension = () => { export const dataProviderExtension = () => {
const { fetchCommon } = useQueryEngine(); const { fetchCommon } = useQueryEngine();
const url = import.meta.env.VITE_SIMPLE_REST_URL; const url = import.meta.env.VITE_GATEWAY_REST_URL;
return { return {
personList: (params: URLSearchParams) => fetchCommon(`${url}/person?${params}`), personList: (params: URLSearchParams) => fetchCommon(`${url}/person?${params}`),

View File

@@ -17,7 +17,7 @@ const fetchJson = (url, options = {}) => {
export const dataProvider = withLifecycleCallbacks( export const dataProvider = withLifecycleCallbacks(
{ {
...simpleRestProvider(import.meta.env.VITE_SIMPLE_REST_URL, fetchJson), ...simpleRestProvider(import.meta.env.VITE_GATEWAY_REST_URL, fetchJson),
...dataProviderExtension(), ...dataProviderExtension(),
}, },
[ [

View File

@@ -2,6 +2,12 @@ export const useQueryEngine = () => {
const defaultHeaders = { const defaultHeaders = {
Accept: "application/json", Accept: "application/json",
"Content-Type": "application/json", "Content-Type": "application/json",
Origin: "http://localhost:3000",
Referer: "http://localhost:3000",
"Access-Control-Allow-Origin": "http://localhost:3000",
"Access-Control-Allow-Headers":
"Origin, X-Requested-With, Content-Type, Accept, X-XSRF-TOKEN, Authorization, Cookie",
"Access-Control-Allow-Credentials": true,
}; };
const response = async (request: Request) => { const response = async (request: Request) => {
@@ -37,6 +43,7 @@ export const useQueryEngine = () => {
return await response( return await response(
new Request(url, { new Request(url, {
mode: "cors",
credentials: "include", credentials: "include",
...(options?.method ? { method: options.method } : { method: "GET" }), ...(options?.method ? { method: options.method } : { method: "GET" }),
...(options.replaceHeaders ...(options.replaceHeaders
@@ -46,6 +53,7 @@ export const useQueryEngine = () => {
...defaultHeaders, ...defaultHeaders,
Authorization: `Bearer ${localStorage.getItem("user")}`, Authorization: `Bearer ${localStorage.getItem("user")}`,
"X-XSRF-TOKEN": localStorage.getItem("user"), "X-XSRF-TOKEN": localStorage.getItem("user"),
"Access-Control-Request-Method": options?.method ? options.method : "GET",
...(options?.headers ? { ...options.headers } : {}), ...(options?.headers ? { ...options.headers } : {}),
}), }),
}), }),