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 {
response = await fetch(
new Request("http://localhost:8080/atsp-idp/token", {
new Request(`${import.meta.env.VITE_AUTH_URL}/atsp-idp/token`, {
method: "POST",
credentials: "include",
body: new URLSearchParams({

View File

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

View File

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

View File

@@ -2,6 +2,12 @@ export const useQueryEngine = () => {
const defaultHeaders = {
Accept: "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) => {
@@ -37,6 +43,7 @@ export const useQueryEngine = () => {
return await response(
new Request(url, {
mode: "cors",
credentials: "include",
...(options?.method ? { method: options.method } : { method: "GET" }),
...(options.replaceHeaders
@@ -46,6 +53,7 @@ export const useQueryEngine = () => {
...defaultHeaders,
Authorization: `Bearer ${localStorage.getItem("user")}`,
"X-XSRF-TOKEN": localStorage.getItem("user"),
"Access-Control-Request-Method": options?.method ? options.method : "GET",
...(options?.headers ? { ...options.headers } : {}),
}),
}),