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 #711
Merged
Merged
Websocket #711
Changes from all commits
Commits
Show all changes
87 commits
Select commit
Hold shift + click to select a range
c4811ca
demo websoket version
computerpunc e32b9fa
Added support for queryStringParameters
computerpunc 1ea68e0
Bug fixes
computerpunc 53e9eef
Run WebSocket endpoint on a different port (http port+1)
computerpunc 602ac7b
GWAPI REST API suppoprt
computerpunc c4c6ea6
Changed the way to get function to post-to-connection
computerpunc 10c377d
Default timeout is 1000ms and can set timeout value via --timeout=
computerpunc bca81cd
Minor Improved logs
computerpunc da8c749
Update README with new ways of sending messages to clients
computerpunc fe4a51d
Merge from upstream/master
computerpunc f527670
Leftovers from merge
computerpunc 4ec82ad
Fix lint errors
computerpunc 4e61aa5
Fix static AWS = { ... }
computerpunc 289e8f5
Fix 2 lint errors
computerpunc ca34ccb
Removed require('aws-sdk/clients/apigatewaymanagementapi');
computerpunc 2f3dfbd
Removed the need for require('serverless-offline').AWS
computerpunc f9600f8
Last commit leftovers
computerpunc f3cf815
Added context and event when calling the handler.
computerpunc 4521b88
Added context and event for connect and disconnect
computerpunc 96dbd16
Merge from master: hapi@18 & hapi-plugin-websocket@2
computerpunc 1e559b7
hapi@18 and hapi-plugin-websocket@2 support
computerpunc 1ea590e
Merge branch 'master' of https://github.com/dherault/serverless-offli…
computerpunc 6638b73
Merge from master and fixes
computerpunc b51ddb5
added support for callback() in handler
computerpunc 381355b
Moved websocket CreateXXX to websocketHelpers.js
computerpunc d45ea7a
Restructure manual_test_websocket to include more projects
computerpunc 66ffe6a
Added serverless.yml with warning
computerpunc 02ce0e7
Support for websocketsApiRouteSelectionExpression
computerpunc 3759b06
Fix lint errors
computerpunc 72a1fc4
Merge branch 'master' of https://github.com/dherault/serverless-offli…
computerpunc 687f901
Merge leftovers
computerpunc b9b0eef
Update README
computerpunc b6c1095
Update README about WebSocket
computerpunc e855a4a
Export on exports
dnalborczyk 53da9c1
Extract multi-value-headers function
dnalborczyk d802dcf
Generate collision resistent ids with cuid (project-wide)
dnalborczyk aa4f977
Add formatToClfTime function
dnalborczyk 2df8ef8
Order props
dnalborczyk fd0637d
Remove unused options
dnalborczyk 8a699ab
Add websocket port option
dnalborczyk 7c34178
Fix spelling
dnalborczyk 193e282
Separate ApiGateway and ApiGatewayWebSockets from Plugin
dnalborczyk 536d1b3
Refactor events setup to offline class
dnalborczyk c51ea7e
Property order nits
dnalborczyk 7b9c942
Spelling
dnalborczyk 5aa2365
Require on top of file
dnalborczyk 25832c8
Use Lambda context for websocket
dnalborczyk 1386954
Add warning for experimental WebSocket support
dnalborczyk 35a3616
Linting
dnalborczyk ca16506
Remove unused this.clients
dnalborczyk d631458
Rename variable
dnalborczyk 0e3b4d8
Add websocket to package.json keywords
dnalborczyk 741287b
Update deps
dnalborczyk d0fe602
Change minimum serverless peer dep to v1.39.0 for websocket support
dnalborczyk a9f4a09
Merge branch 'master' into websocket-fixes
dnalborczyk e54cdc3
Lint and rename folders
dherault fdbd07d
Merge branch 'master' into websocket-fixes
dherault c38a4bc
Display correct protocol on listen
dherault 9247070
Add replay last request feature
dherault 719a14e
Fix http/https --> HTTP
dherault 209a95e
Use option to enable websocket feature
dherault 6959108
Edit documentation
dherault e73983c
Fix travis build lint error
dherault d6eae11
Fix a test that didn't run correctly on AWS
computerpunc 5e19fa6
Fixed test failing when running offline
computerpunc 0f74255
Move to nodejs10.x runtime
computerpunc 9ade958
Merge pull request #720 from computerpunc/websocket-fixes
dherault c5caceb
Merge branch 'master' into websocket-fixes
dherault 7f56a18
Remove websocket feature toggling
dherault a77723e
remove --useWebsocket options
dherault 9d84707
lint
dherault f489781
Update docs
dherault 48c27d8
Merge branch 'master' into websocket-fixes
dherault 1ba79f2
Merge branch 'master' into websocket-fixes
dherault 27639ae
feat: add @connections DELETE route to close websocket
frsechet d5e14aa
fix: add missing printBlankLine method
frsechet e70db4b
chore: add tests for connection close
frsechet 28266f2
Merge pull request #725 from frsechet/websocket-fixes
dherault b83c123
chore: if an error occurs during the $connect action, close the conne…
frsechet 27e1e05
merge master
dnalborczyk b9b1d72
Merge pull request #726 from frsechet/fix/aws-difference
dherault c3fcc4c
Rename getUniqueId to createUniqueId
dnalborczyk b02e874
Merge master
dnalborczyk 4f5ce66
Merge branch 'websocket-fixes' of https://github.com/dherault/serverl…
dnalborczyk c0bea4c
Remove apiGatewayUrl from websocket event
dnalborczyk f901507
fix: don't add body and content-type headers to sigv4 for delete call…
frsechet 09d299a
Merge pull request #729 from frsechet/fix/tests-sigv4-delete-connection
dnalborczyk File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1 @@ | ||
manual_test_nodejs | ||
manual_test_python | ||
manual_test_ruby | ||
manual_test_websocket | ||
**/node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
'use strict'; | ||
|
||
const { exec } = require('child_process'); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/**/serverless.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const AWS = require('aws-sdk'); | ||
|
||
const successfullResponse = { | ||
statusCode: 200, | ||
body: 'Request is OK.', | ||
}; | ||
|
||
module.exports.echo = async (event, context) => { | ||
const action = JSON.parse(event.body); | ||
|
||
await sendToClient(action.message, event.requestContext.connectionId, newAWSApiGatewayManagementApi(event, context)); | ||
|
||
return successfullResponse; | ||
}; | ||
|
||
const newAWSApiGatewayManagementApi = event => { | ||
let endpoint = event.apiGatewayUrl; | ||
|
||
if (!endpoint) endpoint = `${event.requestContext.domainName}/${event.requestContext.stage}`; | ||
const apiVersion = '2018-11-29'; | ||
|
||
return new AWS.ApiGatewayManagementApi({ apiVersion, endpoint }); | ||
}; | ||
|
||
const sendToClient = (data, connectionId, apigwManagementApi) => { | ||
// console.log(`sendToClient:${connectionId}`); | ||
let sendee = data; | ||
if (typeof data === 'object') sendee = JSON.stringify(data); | ||
|
||
return apigwManagementApi.postToConnection({ ConnectionId: connectionId, Data: sendee }).promise(); | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@computerpunc are you sur this line is correct? Wouldn't the endpoint be
localhost:3001
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, unless you have another idea how to inject address (it can be localhost:3001, localhost:3002, etc.) to the function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So what do we input in the docs:
endpoint: process.env.IS_OFFLINE ? 'http://localhost:3001' : undefined
This works well for lambda.invoke.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dherault, @dnalborczyk, @frsechet and others:
Let's start from the beginning:
If AWS would have injected by default
event.requestContext.serverPort
, we wouldn't have this discussion because all information would be at hand.I could have gone with injecting
event.requestContext.serverPort
but I thought that it was too much to handle all the cases (specific port or default, with http or not) so I went withapiGatewayUrl
. Any other suitable name will be fine of course.The drawback, with
process.env.IS_OFFLINE ? 'http://localhost:3001' :
is that the port is hardcoded.What happens if you want to run 2 local instances of the same app?
So we have the following options:
http://localhost:3001
.event
-event.requestContext.serverPort
.process.env.SERVER_PORT
.event.apiGatewayUrl
.apiGatewayUrl
to something else.What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on the end of the day it's really up to the user what to use. I personally did use #3 (env, but for the entire endpoint url), but I might switch to this:
serverless
in the plugin implementation used: https://github.com/serverless/serverless-websockets-plugin/blob/master/example/src/websocket-client.js#L36 as well as https://www.freecodecamp.org/news/real-time-applications-using-websockets-with-aws-api-gateway-and-lambda-a5bb493e9452/There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@computerpunc I couldn't find any information on
apiGatewayUrl
. is that something you added to the event? if so, we might want to remove it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dnalborczyk
https://${config.requestContext.domainName}/${config.requestContext.stage}
is not going to work when running offline. This is what the whole discussion is about. It will not work because the
port
is missing. So the question is how to get the port. Above, I wrote 5 options. Option (1) is my least favorite. Any other is fine. Whatever you find easier to use and more esthetic. No problem to go with hardcoded now (that is removeapiGarewayUrl
) and add whatever needed support later.Since the original PR,
apiGarewayUrl
is injected into the event object (AWS doesn’t do so).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, thanks. then it should be removed, although helpful, it would be quite confusing to add additional properties on the event, other than the aws provided ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as far as the docs are concerned, just go with a simple approach, hardcoded. whatever users are deciding to use is their individual choice. (env, hardcoded, etc.)