2024-04-10 07:43:38 +01:00
|
|
|
package cc.fascinated.config;
|
|
|
|
|
|
|
|
import jakarta.annotation.PostConstruct;
|
|
|
|
import lombok.Getter;
|
2024-04-13 14:07:54 +01:00
|
|
|
import lombok.NonNull;
|
2024-04-11 03:08:17 +01:00
|
|
|
import lombok.extern.log4j.Log4j2;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2024-04-10 07:43:38 +01:00
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
2024-04-13 14:07:54 +01:00
|
|
|
import org.springframework.context.annotation.Bean;
|
2024-04-10 07:43:38 +01:00
|
|
|
import org.springframework.context.annotation.Configuration;
|
2024-04-11 03:08:17 +01:00
|
|
|
import org.springframework.core.env.Environment;
|
2024-04-13 14:07:54 +01:00
|
|
|
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
|
|
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
2024-04-10 07:43:38 +01:00
|
|
|
|
2024-04-11 03:08:17 +01:00
|
|
|
@Getter @Log4j2
|
2024-04-10 13:24:56 +01:00
|
|
|
@Configuration
|
2024-04-10 07:43:38 +01:00
|
|
|
public class Config {
|
|
|
|
public static Config INSTANCE;
|
|
|
|
|
2024-04-11 03:08:17 +01:00
|
|
|
@Autowired
|
|
|
|
private Environment environment;
|
|
|
|
|
2024-04-10 07:43:38 +01:00
|
|
|
@Value("${public-url}")
|
|
|
|
private String webPublicUrl;
|
|
|
|
|
2024-04-11 03:08:17 +01:00
|
|
|
/**
|
|
|
|
* Whether the server is in production mode.
|
|
|
|
*/
|
|
|
|
private boolean production = false;
|
|
|
|
|
2024-04-10 07:43:38 +01:00
|
|
|
@PostConstruct
|
|
|
|
public void onInitialize() {
|
|
|
|
INSTANCE = this;
|
2024-04-13 14:07:54 +01:00
|
|
|
|
2024-04-11 03:08:17 +01:00
|
|
|
String environmentProperty = environment.getProperty("ENVIRONMENT", "development");
|
|
|
|
production = environmentProperty.equalsIgnoreCase("production"); // Set the production mode
|
|
|
|
log.info("Server is running in {} mode", production ? "production" : "development");
|
2024-04-10 07:43:38 +01:00
|
|
|
}
|
2024-04-13 14:07:54 +01:00
|
|
|
|
|
|
|
@Bean
|
|
|
|
public WebMvcConfigurer configureCors() {
|
|
|
|
return new WebMvcConfigurer() {
|
|
|
|
@Override
|
|
|
|
public void addCorsMappings(@NonNull CorsRegistry registry) {
|
|
|
|
// Allow all origins to access the API
|
|
|
|
registry.addMapping("/**")
|
|
|
|
.allowedOrigins("*") // Allow all origins
|
|
|
|
.allowedMethods("*") // Allow all methods
|
|
|
|
.allowedHeaders("*"); // Allow all headers
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2024-04-10 07:43:38 +01:00
|
|
|
}
|