Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ public record AdkWebCorsProperties(

public AdkWebCorsProperties {
mapping = mapping != null ? mapping : "/**";
origins = origins != null && !origins.isEmpty() ? origins : List.of("*");
origins =
origins != null && !origins.isEmpty()
? origins
: List.of("http://localhost:8080", "http://127.0.0.1:8080");
methods =
methods != null && !methods.isEmpty()
? methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.google.adk.web.websocket;

import com.google.adk.web.config.AdkWebCorsProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
Expand All @@ -28,14 +29,19 @@
public class WebSocketConfig implements WebSocketConfigurer {

private final LiveWebSocketHandler liveWebSocketHandler;
private final AdkWebCorsProperties corsProperties;

@Autowired
public WebSocketConfig(LiveWebSocketHandler liveWebSocketHandler) {
public WebSocketConfig(
LiveWebSocketHandler liveWebSocketHandler, AdkWebCorsProperties corsProperties) {
this.liveWebSocketHandler = liveWebSocketHandler;
this.corsProperties = corsProperties;
}

@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
registry.addHandler(liveWebSocketHandler, "/run_live").setAllowedOrigins("*");
registry
.addHandler(liveWebSocketHandler, "/run_live")
.setAllowedOrigins(corsProperties.origins().toArray(new String[0]));
}
}