package com.bonus.canteen.core.utils;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

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

public class SysUtilProxy {
   public String getPrefix(String prefixOn, String prefixOff) {
      if (RequestContextHolder.getRequestAttributes() != null) {
         HttpServletRequest request = ((ServletRequestAttributes)Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
         String headerValue = request.getHeader("X-Env");
         return "online".equals(headerValue) ? prefixOn : prefixOff;
      } else {
         return prefixOff;
      }
   }
}
