You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to connect my Next.js frontend to Spring boot backend in which I am using netty socketio server
I get 404 error in browser console
This is my backend code
@Configuration
public class SocketIOConfig {
@Bean
public SocketIOServer socketIOServer() {
com.corundumstudio.socketio.Configuration config = new com.corundumstudio.socketio.Configuration();
// config.setHostname(host);
// config.setPort(8081);
return new SocketIOServer(config);
}
}
I also added cors in my main application class
@Bean
public FilterRegistrationBean<CorsFilter> corsFilter() {
FilterRegistrationBean<CorsFilter> registrationBean = new FilterRegistrationBean<>();
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();
config.addAllowedOrigin("*");
config.addAllowedHeader("*");
source.registerCorsConfiguration("/**", config);
registrationBean.setFilter(new CorsFilter(source));
registrationBean.setOrder(0);
return registrationBean;
}
@Component
public class SocketIOServerRunner implements CommandLineRunner {
private final SocketIOEvents socketIOEvents;
@Autowired
public SocketIOServerRunner(SocketIOEvents socketIOEvents) {
this.socketIOEvents = socketIOEvents;
}
@Override
public void run(String... args) {
socketIOEvents.init();
}
}
Your filter is applied only for Spring web server, but netty-socket.io starts separate netty server and uses another port which you can specify in com.corundumstudio.socketio.Configuration, it also contains getter/setter methods for allowed origin and headers
@shutuper Thanks for the reply. I updated the code to
@Configuration
public class SocketIOConfig {
@Bean
public SocketIOServer socketIOServer() {
com.corundumstudio.socketio.Configuration config = new com.corundumstudio.socketio.Configuration();
config.setPort(8081);
config.setOrigin("*"); // Allow requests from all origins
return new SocketIOServer(config);
}
}
But still i get cors issue, I am accessing http://localhost:8081 from frontend side
I am trying to connect my Next.js frontend to Spring boot backend in which I am using netty socketio server
I get 404 error in browser console
This is my backend code
I also added cors in my main application class
This is my frontend NextJs code
Complete source code here
Encountering a 404 error in the browser console when trying to connect your Next.js frontend to your Spring Boot backend using Netty Socket.IO server
The text was updated successfully, but these errors were encountered: