Websocket $connect路由:是否可以在“$connect route”中传递查询字符串/自定义标头以及“connectionId”?

0

【以下的问题经过翻译处理】 我正在使用使用HTTP集成与我的EC2中的NodeJS后端通信的Websocket API。我成功地通过请求模板在“$connect route”上传递了“connectionId”。

但是,在这样做时,我无法传递任何自定义标题和查询字符串参数。我尝试使用“$request.querystring”和“$input.params”参数通过请求模板传递这些值。但这没有起作用。

当勾选“使用HTTP代理集成”时,查询字符串和自定义标头均正确传递到后端,但是,此时“connectionId”未传递。

我的当前请求模板是:

{
  "connectionId": "$context.connectionId",
  "domain": "$context.domainName",
  "stage": "$context.stage",
  "requestId": "$context.requestId",
  "body": "$input.body"
}

我的问题是:是否可以在“$connect route”中传递查询字符串/自定义标头以及“connectionId”?

profile picture
ESPERTO
posta 6 mesi fa10 visualizzazioni
1 Risposta
0

【以下的回答经过翻译处理】 在撰写时,WebSocket API不支持模板中的查询字符串或标头。您可以在此处查看所有支持的变量:https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-websocket-api-mapping-template-reference.html

我同意,在$connect路线中支持查询字符串/标头很有意义,而其他路线则不支持。我将为此创建一个待办事项。

profile picture
ESPERTO
con risposta 6 mesi fa

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande