@@ -61,15 +61,19 @@ export interface SendStrategy {
6161 * Used when running in proxy mode with a broker URL configured.
6262 */
6363export class BrokerSendStrategy implements SendStrategy {
64- constructor ( private brokerUrl : string ) { }
64+ constructor ( private brokerUrl : string , private brokerApiKey ?: string ) { }
6565
6666 async send ( request : SendRequest ) : Promise < SendOutcome > {
6767 try {
68+ const headers : Record < string , string > = {
69+ 'content-type' : 'application/json' ,
70+ } ;
71+ if ( this . brokerApiKey ) {
72+ headers [ 'x-api-key' ] = this . brokerApiKey ;
73+ }
6874 const upstream = await fetch ( `${ this . brokerUrl } /api/send` , {
6975 method : 'POST' ,
70- headers : {
71- 'content-type' : 'application/json' ,
72- } ,
76+ headers,
7377 body : JSON . stringify ( {
7478 to : request . to ,
7579 message : request . message ,
@@ -159,6 +163,7 @@ export class DirectSendStrategy implements SendStrategy {
159163export interface CreateSendStrategyOptions {
160164 brokerProxyEnabled : boolean ;
161165 brokerUrl ?: string ;
166+ brokerApiKey ?: string ;
162167 relaycastConfig ?: RelaycastConfig | null ;
163168 dataDir : string ;
164169}
@@ -171,7 +176,7 @@ export interface CreateSendStrategyOptions {
171176 */
172177export function createSendStrategy ( opts : CreateSendStrategyOptions ) : SendStrategy | null {
173178 if ( opts . brokerProxyEnabled && opts . brokerUrl ) {
174- return new BrokerSendStrategy ( opts . brokerUrl ) ;
179+ return new BrokerSendStrategy ( opts . brokerUrl , opts . brokerApiKey ) ;
175180 }
176181
177182 if ( opts . relaycastConfig ) {
0 commit comments