Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

41 rader
1.9 KiB

  1. package com.ffii.lioner.config;
  2. import org.springframework.context.annotation.Bean;
  3. import org.springframework.context.annotation.Configuration;
  4. import org.springframework.web.servlet.config.annotation.CorsRegistry;
  5. import org.springframework.web.servlet.config.annotation.EnableWebMvc;
  6. import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
  7. import org.springframework.web.servlet.view.InternalResourceViewResolver;
  8. @Configuration
  9. @EnableWebMvc
  10. public class WebConfig implements WebMvcConfigurer {
  11. @Override
  12. public void addCorsMappings(CorsRegistry registry) {
  13. registry.addMapping("/**") // Apply to all API endpoints
  14. .allowedHeaders("*")
  15. // **** CRITICAL FIX HERE ****
  16. .allowedOrigins(
  17. "http://localhost", // If you test locally via Nginx at http://localhost
  18. "http://127.0.0.1", // Sometimes browsers resolve localhost to 127.0.0.1
  19. "http://52.175.15.19", // Your 2fi-uat frontend IP
  20. "http://localhost:3000" // If you ever run React dev server directly
  21. // Add any other specific domains/IPs/ports where your frontend will be hosted
  22. )
  23. // You had .exposedHeaders("filename") - keep if you need to read custom response headers
  24. .exposedHeaders("filename")
  25. // You had .allowedMethods("GET", "POST", "PUT", "DELETE", "HEAD") - This is missing "OPTIONS"
  26. .allowedMethods("GET", "POST", "PUT", "DELETE", "HEAD", "OPTIONS") // **** IMPORTANT: Add OPTIONS ****
  27. // You had .allowedHeaders("*") duplicated - harmless, but the first one is enough
  28. // .allowedHeaders("*")
  29. .allowCredentials(true)
  30. .maxAge(3600); // Recommended: Caches preflight results for 1 hour
  31. }
  32. @Bean
  33. public InternalResourceViewResolver defaultViewResolver() {
  34. return new InternalResourceViewResolver();
  35. }
  36. }