I'm trying to call an API in the back-end, but I just keep getting a connection refused error. The back-end is inside a tomcat server deployed in BlueHost; the framework is spring-boot; its war file is already deployed in webapp folder; and I've already included the following filter in web.xml to allow for CORS
<filter>
<filter-name>CorsFilter</filter-name>
<filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
<init-param>
<param-name>cors.allowed.orgins</param-name>
<param-value>*</param-value>
</init-param>
<init-param>
<param-name>cors.allowed.methods</param-name>
<param-value>GET,POST,HEAD,OPTIONS,PUT</param-value>
</init-param>
<init-param>
<param-name>cors.allowed.headers</param-name>
<param-value>Content-Type,X-Requested-With,accept,Origin,Access-Control-Request-Method,Access-Control-Request-Headers</param-value>
</init-param>
<init-param>
<param-name>cors.exposed.headers</param-name>
<param-value>Access-Control-Allow-Origin,Access-Control-Allow-Credentials</param-value>
</init-param>
<init-param>
<param-name>cors.support.credentials</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CorsFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Since I believe CORS is already enabled by default in Spring-boot, I didn't bother to define cors configuration bean file; even when I did, I was still receiving the error. I also made sure that my client request didn't include any illegal headers. However, it's doing a pre-flight request with Content Type. It's the following:
let httpReq = {
method: type,
headers: {
"Content-Type": "application/json",
Accept: "application/json"
},
referrer: window.location.href, // https://web.dev/referrer-best-practices/
referrerPolicy: "strict-origin-when-cross-origin",
mode: "cors",
credentials: "same-origin",
cache: "default",
redirect: "error"
};
await fetch("http://localhost:8080" + api, httpReq)
.then(response => {
return response.json();
})
I restarted apache and tomcat several times, still nothing. I was also unable to see any helpful logs from Tomcat, and I also made sure that the process is still working with netstat. I'm lost on what to do. Any suggestions would be appreciated.
Thanks
the issue was stemming from a misconfigured include file in httpd.conf and a misconfigured pathing inside my pom.xml.