net.nemerosa.ontrack.boot.support.DevWebConfig Maven / Gradle / Ivy
package net.nemerosa.ontrack.boot.support;
import net.nemerosa.ontrack.common.RunProfile;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import java.io.File;
@Configuration
@Profile(RunProfile.DEV)
public class DevWebConfig extends WebMvcConfigurerAdapter {
private final Log log = LogFactory.getLog(DevWebConfig.class);
@Autowired
private DevSettings devSettings;
/**
* At development time, we want the static resources served directly
* from the ontrack-web
project, under the build/web/dev
and build/web/prod
* directories.
*/
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
// Warning
log.warn("[dev] Running in DEV mode");
// Compiled production resources
String prod = getPath(devSettings.getProd());
log.info("[dev] Compiled prod web resources from: " + prod);
registry.addResourceHandler("/fonts/**").addResourceLocations(prod + "/fonts/");
// Compiler dev resources
String dev = getPath(devSettings.getDev());
log.info("[dev] Compiled dev web resources from: " + dev);
registry.addResourceHandler("/css/**").addResourceLocations(dev + "/css/");
registry.addResourceHandler("/templates/**").addResourceLocations(dev + "/templates/");
registry.addResourceHandler("index.html").addResourceLocations(dev + "/");
registry.addResourceHandler("graphiql.html").addResourceLocations(dev + "/");
// Direct access to the sources
String source = getPath(devSettings.getSrc());
log.info("[dev] Web sources from: " + source);
registry.addResourceHandler("/app/**").addResourceLocations(source + "/app/");
registry.addResourceHandler("/graphiql/**").addResourceLocations(source + "/graphiql/");
registry.addResourceHandler("/assets/**").addResourceLocations(source + "/assets/");
// Vendor resources
String vendor = getPath(devSettings.getVendor());
log.info("[dev] Vendor sources from: " + vendor);
registry.addResourceHandler("/vendor/**").addResourceLocations(vendor + "/");
}
private String getPath(String dirName) {
return "file:" + new File(
devSettings.getWeb(),
dirName
).getAbsolutePath();
}
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("forward:/index.html");
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy