java - AxiosError: Network Error work in some device and not in others - Stack Overflow

I'm working on a project using ReactJS as the frontend, deployment on AWS Amplify, and Spring Boot

I'm working on a project using ReactJS as the frontend, deployment on AWS Amplify, and Spring Boot as the backend deployed on an AWS instance. Some users are getting this error when they try to register:

NetworkError:axios Error

Yet for other users it works fine.

here is my code:

registration.js

static BASE_URL = ";;
static async register(userData) {
    console.log(JSON.stringify(userData));
    try {
        const response = await axios.post(
            `${UserService.BASE_URL}/auth/register`,
            userData,
            {
                headers: {
                    Accept: "application/json",
                    "Content-Type": "application/json",
                },
            }
        );
        console.log(response.data);
        return response.data;
    } catch (err) {
        throw err;
    }
}

my spring boot backend:

@Bean
CorsConfigurationSource corsConfigurationSource(){
    CorsConfiguration configuration=new CorsConfiguration();
    configuration.setAllowedOrigins(List.of(";));
    configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT",       "DELETE","HEAD","OPTIONS"));

    configuration.setAllowedHeaders(Arrays.asList(HttpHeaders.AUTHORIZATION
            ,HttpHeaders.CONTENT_TYPE
            ,HttpHeaders.ACCEPT));
    configuration.setAllowCredentials(true); // Allow credentials
    configuration.setMaxAge(3600L); // Optional: Set max age for preflight requests
    configuration.addAllowedHeader("*");
    UrlBasedCorsConfigurationSource source=new UrlBasedCorsConfigurationSource();
    source.registerCorsConfiguration("/**",configuration);
    return source;
}   

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744274169a4566247.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信