New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Websocket support #674
Websocket support #674
Conversation
POST to /@connections/{connectionId} to send message to client at connectionId.
Here's the new way: const endpoint=event.requestContext.domainName+'/'+event.requestContext.stage; const apiVersion='2018-11-29'; let API=null; if (!process.env.IS_OFFLINE) { API = require('aws-sdk'); require('aws-sdk/clients/apigatewaymanagementapi'); } else { API = require('serverless-offline').AWS; } return new API.ApiGatewayManagementApi({ apiVersion, endpoint });
1. Action of routes. 2. Listening on WS message sending via REST API.
@computerpunc the build is failing |
static properties were introduced by one of the newer V8s available only in node v12+: https://github.com/dherault/serverless-offline/pull/674/files#diff-1fdf421c05c1140f6d71444ea2b27638R169 |
@computerpunc just gave it a quick try. great job!! one thing I noticed is that the it seems to be working in general, but haven't looked or tried everything yet. partially also because of the empty context object. edit: actually, the |
Doesn't seem to be needed anymore as a workaround in aws-sdk.
Use plain vanilla AWS SDK: let endpoint=event.apiGatewayUrl; if (!endpoint) endpoint = event.requestContext.domainName+'/'+event.requestContext.stage; const apiVersion='2018-11-29'; return new AWS.ApiGatewayManagementApi({ apiVersion, endpoint });
question, either approving this or the Hapi upgrade will break the other PR. Is there a choice on which will go in, which will require changes for the other developer? |
I think I'll merge the Hapi upgrade first |
Hey guys, this implementation works with Authorizer?
|
@dherault I think it might be better, as I think this PR still needs a bit of work. I wanna look into the I also looked through the code and did some incremental/fairly small changes, to get a better understanding, but also to reduce some of the complexity. I'll do a PR with it later, and then try to rebase v18 on top of it, if possible -- unless you are already on it. Afterwards I wanna look closer into this PR. @mataide I don't think so. |
I reviewed it too and am willing to merge. The comments @dnalborczyk gave should be addressed first. Can't wait to use it for my next serverless project, it requires websockets! |
(@dherault, JUST saw your comment 😃 ) I pulled your PR into a branch: https://github.com/dherault/serverless-offline/tree/websockets I think it's probably better and also easier to collaborate in the branch. on first sight it doesn't seem to have any effect on any of the other code, other than sharing the what do you guys think? |
Agreed! |
I'm using websockets for my current project as well. although, development is quite cumbersome. But as it seems not for long! |
Please update the README as well. You're almost there @computerpunc! |
Using the existing lambda context is the way to go but at the current moment, I went with a solution that is decoupled. Most if not all of the code that could have been shared is not shared but copy/paste. I didn't want to accidentally degrade the HTTP part of the code. This in not only true for the present state but also for the future when I'll need to fix future bugs. I suggest that for v5.1, we can think of some kind of refactoring the HTTP and WS parts in which we'll use shared code for lambda context, server startup, etc. for both parts.
No problem. I'll put them in a separate file.
promise and callback are already handled (callback just recently) but context method is not recommended anymore by AWS and I'm not sure it's even supported in nodejs 8.10 runtime.
OK. I'll take a look into it.
Sure :) |
@computerpunc awesome, thanks! I'm really looking forward for having this released!
makes sense.
that's true, it's I'm planning on doing a couple PRs against the |
Maybe we should reopen this PR against the branch websockets ? |
I tried to add authorizer support but I don't think I'll be able to as there's a bug with authorization scheme and strategy in hapi-plugin-websocket in which it first opens a connection and only then sends checks for auth. I can write some sort of code to sync things up but it's a lot of work and it may be easier to fix it at the source (hapi-plugin-websocket). And now to implementing |
In the form of $request.body.x.y.z
… into websocket-support
Guys, |
incredible job @computerpunc !!! Let me pull this PR into the |
I played with the websocket branch over the weekend a bit and added some small changes:
this.apiGatewayWebSocket._createWsAction(fun, funName, servicePath, funOptions, event);
this.apiGateway._createRoutes(event, funOptions, protectedRoutes, funName, servicePath, serviceRuntime, defaultContentType, key, fun); is more or less temporary, and can be greatly reduced and cleaned up over time. also played a bit with websocketsApiRouteSelectionExpression, which seems to work as intended. there's a bunch of other stuff missing for a full blown "offline" websocket simulation, but I think that's something which can be extended over time when the need arises. I also have other additions and changes in stashes all over the place, but I'd rather have this PR released as well before adding/changing anything more. |
Looking forward to see this PR released. In the meanwhile, I'm working on supporting |
I need some time to review this. @dnalborczyk should we merge this yet ? If we both review green I merge. |
@dherault I added the changes in a branch here: https://github.com/dherault/serverless-offline/commits/websocket-fixes which includes this PR plus the above mentioned changes. do you want me to open a new PR? or do you want to merge yourself locally? |
Let's open a new PR! |
closing in favor of #711 no worries @computerpunc , your work is still in the other PR (every single commit). |
AWS WebSocket support that includes:
I haven't tested everything, e.g., auth and https/wss.
I haven't yet updated the main README file.
Usage Assumption - In order to send messages back to clients
POST http://localhost:3001/@connections/{connectionId}
Or,
const endpoint=event.requestContext.domainName+'/'+event.requestContext.stage;
const apiVersion='2018-11-29';
let API=null;
if (!process.env.IS_OFFLINE) {
API = require('aws-sdk');
require('aws-sdk/clients/apigatewaymanagementapi');
} else {
API = require('serverless-offline').AWS;
}
new API.ApiGatewayManagementApi({ apiVersion, endpoint });