Skip to content

Commit

Permalink
fix: socket io config
Browse files Browse the repository at this point in the history
  • Loading branch information
kuoche1712003 committed Feb 9, 2025
1 parent a14f11e commit 0af4d72
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,27 @@ package tw.waterballsa.gaas.spring.configs.socketio

import com.corundumstudio.socketio.SocketIOServer
import com.corundumstudio.socketio.annotation.SpringAnnotationScanner
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration

@Configuration
@EnableConfigurationProperties(SocketIOProperties::class)
class SocketIOConfig{
private val logger: Logger = LoggerFactory.getLogger(SocketIOConfig::class.java)

@Bean
fun socketIOServer(
socketIOProperties: SocketIOProperties,
): SocketIOServer {
val configuration = com.corundumstudio.socketio.Configuration().apply {
with(socketIOProperties) {
hostname = socketHost
port = socketPort
allowHeaders = "Authorization, CustomHeaderName"
}
hostname = socketIOProperties.host
port = socketIOProperties.port
allowHeaders = "Authorization, CustomHeaderName"
}
logger.info("SocketIO server host: ${configuration.hostname}")
return SocketIOServer(configuration)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package tw.waterballsa.gaas.spring.configs.socketio

import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.boot.context.properties.ConstructorBinding

@ConfigurationProperties(prefix = "socket.io")
data class SocketIOProperties (
val socketHost: String = "127.0.0.1",
val socketPort: Int = 9001,
){
}
@ConfigurationProperties(prefix = "socketio")
data class SocketIOProperties @ConstructorBinding constructor(
val host: String = "127.0.0.1",
val port: Int = 9001,
)

0 comments on commit 0af4d72

Please sign in to comment.