package cclotus.ruoyi.ext.web.spa;

import org.springframework.core.io.Resource;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.resource.PathResourceResolver;
import org.springframework.web.servlet.resource.ResourceResolverChain;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

public class SpaPathResourceResolver extends PathResourceResolver {
    @Override
    protected Resource resolveResourceInternal(@Nullable HttpServletRequest request, String requestPath,
                                               List<? extends Resource> locations, ResourceResolverChain chain) {
        Resource tryFiles =  super.resolveResourceInternal(request, requestPath, locations, chain);
        if (tryFiles == null) {
            tryFiles = super.resolveResourceInternal(request, "index.html", locations, chain);
        }
        return tryFiles;
    }
}
