2021-03-16 14:25:15 +01:00
|
|
|
package eu.openaire.urls_controller;
|
|
|
|
|
|
|
|
|
2021-11-09 22:59:27 +01:00
|
|
|
import eu.openaire.urls_controller.configuration.ImpalaConnector;
|
2021-03-16 14:25:15 +01:00
|
|
|
import eu.openaire.urls_controller.util.UriBuilder;
|
|
|
|
import org.springframework.boot.CommandLineRunner;
|
|
|
|
import org.springframework.boot.SpringApplication;
|
|
|
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
|
import org.springframework.core.env.Environment;
|
|
|
|
import org.springframework.web.cors.CorsConfiguration;
|
|
|
|
import org.springframework.web.cors.CorsConfigurationSource;
|
|
|
|
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
|
|
|
|
2021-11-09 22:59:27 +01:00
|
|
|
import javax.annotation.PreDestroy;
|
2021-03-16 14:25:15 +01:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Collections;
|
|
|
|
|
|
|
|
@SpringBootApplication
|
|
|
|
@EnableScheduling
|
|
|
|
public class Application {
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
SpringApplication.run(Application.class, args);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
public CorsConfigurationSource corsConfigurationSource() {
|
|
|
|
CorsConfiguration configuration = new CorsConfiguration();
|
|
|
|
configuration.setAllowedOrigins(Collections.singletonList("*"));
|
|
|
|
configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"));
|
|
|
|
configuration.setAllowedHeaders(Arrays.asList("authorization", "content-type", "x-auth-token"));
|
|
|
|
configuration.setExposedHeaders(Collections.singletonList("x-auth-token"));
|
|
|
|
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
|
|
|
source.registerCorsConfiguration("/**", configuration);
|
|
|
|
return source;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-09 22:59:27 +01:00
|
|
|
@PreDestroy
|
|
|
|
public static void preDestroy()
|
|
|
|
{
|
|
|
|
if ( ImpalaConnector.hikariDataSource != null )
|
|
|
|
ImpalaConnector.hikariDataSource.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-16 14:25:15 +01:00
|
|
|
@Bean
|
|
|
|
public CommandLineRunner setServerBaseUrl(Environment environment)
|
|
|
|
{
|
|
|
|
return args -> new UriBuilder(environment);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|