I have a React application based on Typescript which is hosted on my PC.
I use Spring gateway to forward requests to another microservice. GET requests are working fine but for POST requests I get:
Access to XMLHttpRequest at 'http://1.1.1.1:8080/api/support/tickets/create' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
I’m hitting this Spring Cloud Gateway issue: https://github.com/spring-cloud/spring-cloud-gateway/issues/229
Spring cloud configuration:
@Bean
public RouteLocator routes(RouteLocatorBuilder builder, LoggingGatewayFilterFactory loggingFactory) {
return builder.routes()
.route("route_id",
route -> route
.path("/api/support/tickets/**")
.filters(f -> f.rewritePath("/api/support/tickets/(?<RID>.*)", "/support/tickets/${RID}"))
.uri("lb://merchant-hub-admin-service")
)
.build();
}
React code:
export async function getTicket(id: string) {
return await axios.get(`${baseUrl}/support/tickets/ticket/${id}`);
}
export async function postTicket(
data: TicketFullDTO
): Promise<AxiosResponse<TicketFullDTO>> {
return await axios.post<TicketFullDTO>(
`${baseUrl}/support/tickets/create`, data);
}
Do you know how I can disable OPTIONS
request before POST
and DELETE
requests?