package com.ffii.lioner.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {
   
  @Override
  public void addCorsMappings(CorsRegistry registry) {
      registry.addMapping("/**")
              .allowedOrigins(
                  "http://localhost:3000",     // React dev server
                  "http://localhost",
                  "http://127.0.0.1",
                  "http://10.40.0.4",
                  "http://20.2.170.164",
                  "https://20.2.170.164",
                  "https://forms.lioner.com"
              )
              .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS", "HEAD")
              .allowedHeaders("*")
              .allowCredentials(true)
              .maxAge(3600);
  }

  @Bean
  public InternalResourceViewResolver defaultViewResolver() {
    return new InternalResourceViewResolver();
  }

}