TsgcWebSocketServer_HTTPAPI › 事件 › OnBeforeBinding
在服务器绑定到已配置 URL 之前触发,以便检查或自定义绑定列表。
property OnBeforeBinding: TsgcWSHTTPAPIBeforeBinding;
// TsgcWSHTTPAPIBeforeBinding = procedure(Sender: TObject; const Bindings: TStrings) of object
—
OnBeforeBinding 在组件收集要向 HTTP.SYS 注册的 URL(来自 Host/Port 对以及通过 Bindings.NewBinding 添加的条目)之后、实际保留这些 URL 前缀之前触发。Bindings 参数是 URL 前缀的 TStrings 列表(例如 "http://127.0.0.1:80/" 或 "https://+:443/");可清除、添加或重写此列表中的条目,以更改内核驱动程序将监听的端点。这是在运行时注入每环境绑定而无需修改设计器属性的正确位置。
procedure OnBeforeBinding(Sender: TObject; const Bindings: TStrings);
begin
Bindings.Clear;
Bindings.Add('http://127.0.0.1:80/');
Bindings.Add('http://+:8080/api/');
end;