After completing the test via apic on my laptop, I put it up as a docker container on awsec2 Ubuntu server, but it doesn’t connect.
Just in case, I tried to do the same by putting the container on the local with a docker, but it connects normally.
I don’t know why I can’t connect when there is no separate error code in the server log.
I opened the server 8080 port, and the restapi http:// connection works well. But the ws:// connection is not working.
Only containers uploaded from the server are not connected, so what’s the problem..
This command was created when uploading docker containers.
docker run -d -e PORT=8080 -p 8080:8080 --name test-server --add-host host.docker.internal:host-gateway --restart always imagename
- WebConfig
@Configuration
public class WebConfig implements WebMvcConfigurer {
private static final String CORS_URL_PATTERN = "/*";
private static final String CORS_URL = "*";
private static final String CORS_METHOD = "*";
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping(CORS_URL_PATTERN)
.allowedOrigins(CORS_URL)
.allowedMethods(CORS_METHOD);
}
}
- WebSocketConfig
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
registry.setApplicationDestinationPrefixes("/app");
registry.enableSimpleBroker("/topic");
}
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/ws")
.setAllowedOrigins("*");
}
}
- connection success(localhost)
connection success
connection success message
- connection fail(server ip)
connection fail
connection fail message
jaemoon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.