package cd.casic.ops.ui;

import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @description: 不想弄nginx配置，直接启动
 * @author: mianbin
 * @date: 2025/5/31 0:19
 * @version: 1.0
 */
@Configuration(proxyBeanMethods = false)
public class UiConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 管理后台 Ops 的配置
        registry.addResourceHandler("/yudao/**", "/yudao/", "/yudao")
                .addResourceLocations("classpath:/yudao/")
                .addResourceLocations(new ClassPathResource("/yudao/index.html") {

                    @Override
                    public Resource createRelative(String relativePath) {
                        return this;
                    }

                })
        ;
    }

    @Component
    public static class UiApplicationRunner implements ApplicationRunner {

        @Override
        public void run(ApplicationArguments args) throws Exception {
            System.out.println("Ops 项目 无服务启动版：http://127.0.0.1:4096/casic/");
        }

    }
}
