Serverless-offline: Websocket support

Created on 21 Feb 2019  路  7Comments  路  Source: dherault/serverless-offline

websocket support is going into core from 1.38.0 (https://github.com/serverless/serverless/releases/tag/v1.38.0). Is there any chance that there is a plan to implement that in serverless offline? Saw in an earlier thread regarding this that it wasn't going to be supported.

enhancement

Most helpful comment

All 7 comments

Well, I know for a fact that to support websockets you have to boot another server. That would need a lot of modifications especially on the route creation part. I'd gladly accept a PR implementing it but cannot create it.

I鈥檓 not sure that it would necessarily need to boot a separate server. There鈥檚 a few middlewares for hapi that implement websockets. The challenge that I鈥檝e seen is that most of them are opinionated about the protocol... some even ship with their own client library.

The point, though, is that it may be feasible to implement a hapi middleware that speaks websockets in the dialect that API Gateway expects: https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-websocket-api-overview.html

As I am trying to implement https://github.com/wzr1337/rsi.server serverless right now, WebSocket support would be a big plus for me too. ;)

I think a good start might be https://github.com/rse/hapi-plugin-websocket, version 1.2.19 is compatible with the version of hapi that serverless-offline uses. I've managed to get it to work but not getting a correct event or context into the handlers nor getting the authorizer function called on connect making it somewhat useless for the general public. I'm using it now with some shared state and hard coded presumptions but someone who knows the current code might be able to fix that. If someone is up for that I could perhaps make a PR or something as a starter.

@triptec you can make a PR, I'll look into it to make it work.

Was this page helpful?
0 / 5 - 0 ratings