package cn.stylefeng.guns.modular.deploy;


import cn.hutool.core.io.IoUtil;
import cn.hutool.core.io.resource.ResourceUtil;
import jakarta.servlet.ServletOutputStream;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

@Controller
public class IndexController {

    @GetMapping("/guns-devops")
    public void index(HttpServletResponse response) throws IOException {
        renderIndex(response);
    }

    private void renderIndex(HttpServletResponse response) throws IOException {
        ServletOutputStream outputStream = response.getOutputStream();
        response.addHeader("Content-Type", "text/html");
        response.addHeader("Cache-Control", "no-cache");
        response.addHeader("Cache-Control", "no-cache, no-store, private, must-revalidate, proxy-revalidate");
        String indexContent = ResourceUtil.readStr("classpath:/guns-devops/index.html", StandardCharsets.UTF_8);
        IoUtil.write(outputStream, StandardCharsets.UTF_8, true, indexContent);
    }

}
