这是我的表象:
const API_ROOT = import.meta.env.VITE_API_ROOT as string;
export function rest(url: string, body?: unknown, method?: string, headers?: HeadersInit){
return fetch(url, {
method: method ?? (body ? "POST" : "GET"),
headers: {
Content-Type : application/json ,
...headers
},
body: body ? JSON.stringify(body) : undefined
})
.then(response => response.ok
? response.json()
: response.json().then(err => Promise.reject(err)) )
}
export function api(action: string, body?: unknown, method?: string, headers?: HeadersInit){
return rest(`${API_ROOT}/${action}`, body, method, headers);
}
我的评价职能包括:
CORS(app)
并适当列入我试图进入的路线蓝图。 当我使用邮政员时,该路线就行驶。
我试图通过人工方式确定索再解放联盟的负责人。
@app.after_request
def after_request(response):
response.headers.add( Access-Control-Allow-Origin , http://localhost:5173 )
response.headers.add( Access-Control-Allow-Headers , Content-Type )
response.headers.add( Access-Control-Allow-Methods , OPTIONS, GET )
response.headers.add( Access-Control-Allow-Credentials , true )
return response
我也试图在我的道路上增加一个勋章:
@cross_origin(origin="http://localhost:5173", supports_credentials=True)
我试图在方法上将《任择议定书》方法人工添加到我的其余部分:
const actualMethod = method === "OPTIONS" ? "OPTIONS" : method ?? (body ? "POST" : "GET");
But nothing is working! I still get the error: Access to fetch at http://localhost:8000/api/v1/ports/getports from origin http://localhost:5173 has been blocked by CORS policy: Response to preflight request doesn t pass access control check: It does not have HTTP ok status.
And this one: GET http://localhost:8000/api/v1/ports/getports net::ERR_FAILED
而后又发生了Fetch错误。
如果人人都能有热情的见解,就会感谢你!