dherault / serverless-offline

Emulate AWS λ and API Gateway locally when developing your Serverless project
MIT License
5.18k stars 793 forks source link

Not able to connect serverless-offline websocket on browser #1670

Open anmol098 opened 1 year ago

anmol098 commented 1 year ago

I have a node project and I have created websocket with serverless and it's running on port 6000. When I try to connect from wscat it's able to connect

wscat -c ws://localhost:6000.

But when I try to connect from browser using Websocket browser api it fails to connect the connect request is not even reaching the lambda function On browser I am using

new WebSocket('ws://localhost:6000') Browser just throws error connection failed with no reason.

When I deploy cloud formation file to aws that websocket I am able to connect

Please help if I am missing anything.

malyz01 commented 11 months ago

Hi,

I have the same issue as above. I tried connecting via insomnia or wscat to ws://localhost:4000 but I get:

wscat error:

image

insomnia error:

image

sls offline:

image

Serverless config:

service: websocket
frameworkVersion: "3"

plugins:
  - serverless-webpack
  - serverless-offline

provider:
  name: aws
  runtime: nodejs14.x
  websocketsApiName: websockets-api
  websocketsApiRouteSelectionExpression: $request.body.action

custom:
  serverless-offline:
    websocketPort: 4000

functions:
  - socket-connect:
      handler: src/socket.connect
      events:
        - websocket:
            route: $connect

package.json dependencies version:

"serverless": "^3.24.1",
"serverless-offline": "^12.0.4",
"serverless-webpack": "^5.8.0",  

Am I missing something as well? (the webpack is for typescript codes)