fix WebConfig for angular routing
This commit is contained in:
parent
bb7eb594a0
commit
ab39f5a010
@ -3,13 +3,19 @@ package de.ph87.homeautomation.web;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
import org.springframework.web.servlet.resource.PathResourceResolver;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Configuration
|
||||
@EnableWebSecurity
|
||||
@ -33,17 +39,18 @@ public class WebConfig extends WebSecurityConfigurerAdapter implements WebMvcCon
|
||||
registry.addMapping("/**").allowCredentials(true).allowedOrigins("http://localhost:4200").allowedMethods("*");
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void addResourceHandlers(final ResourceHandlerRegistry registry) {
|
||||
// registry
|
||||
// .addResourceHandler("/**")
|
||||
// .addResourceLocations("classpath:/resources/")
|
||||
// .resourceChain(true)
|
||||
// .addResolver(new PathResourceResolver() {
|
||||
// protected Resource getResource(String resourcePath, Resource location) throws IOException {
|
||||
// Resource requestedResource = location.createRelative(resourcePath);
|
||||
// return requestedResource.exists() && requestedResource.isReadable() ? requestedResource : new ClassPathResource("/resources/index.html");
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
@Override
|
||||
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
|
||||
registry
|
||||
.addResourceHandler("/**")
|
||||
.addResourceLocations("classpath:/resources/")
|
||||
.resourceChain(true)
|
||||
.addResolver(new PathResourceResolver() {
|
||||
protected Resource getResource(String resourcePath, Resource roomLocation) throws IOException {
|
||||
Resource requestedResource = roomLocation.createRelative(resourcePath);
|
||||
return requestedResource.exists() && requestedResource.isReadable() ? requestedResource : new ClassPathResource("/resources/index.html");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user