subscriptionless icon indicating copy to clipboard operation
subscriptionless copied to clipboard

Allow custom domain mappings

Open devlsh opened this issue 4 years ago • 9 comments
trafficstars

Currently the Management API endpoint is hard-coded to be the supplied domain name, likely since it'd be the same execute-api URL. However I'd like to map the front-facing WebSocket API to a custom domain and supply the execute-api URL myself (I use AWS CDK and could easily pass-through the URL via env vars).

I think it would be around this area: https://github.com/andyrichardson/subscriptionless/blob/master/src/utils/aws.ts#L28

devlsh avatar Sep 05 '21 23:09 devlsh

Other than this small issue, I've successfully set this up now - and it's working great! I had a few pain points with the implementation, which I'll create a separate issue/PR for, but all seems to be working well on my stack:

  • Working along-side Apollo Server for Query/Mutation
  • Took some fiddling but the stack set-up on AWS CDK seems to be complete
  • Works well with graphql-codegen generated subscription hooks

When I get a little more time, I'll write a small example and PR it to demonstrate Apollo + AWS CDK usage

devlsh avatar Sep 06 '21 03:09 devlsh

Hey @oyed thanks for the report and feedback!

The reason the domain name and stage isn't currently configurable is because connections are (I believe) unique to a given domain/stage.

I can't find any documentation confirming or contradicting this assumption but let me know if you are seeing otherwise.

I can't think of a reason why we would want to attempt to message on a socket via an API that isn't the one that established the connection - do you have any more info on why you might want to do this?

andyrichardson avatar Sep 06 '21 15:09 andyrichardson

Took some fiddling but the stack set-up on AWS CDK seems to be complete

Feel free to share your config - happy to merge in a CDK (or CF?) example if its not super straight forward.

andyrichardson avatar Sep 06 '21 15:09 andyrichardson

The reason the domain name and stage isn't currently configurable is because connections are (I believe) unique to a given domain/stage.

Correct - however when developing locally, proxying or just wanting a domain infront of the WS API Gateway, allowing an option for designating the URL is required (Breaks my local dev, requires using a dynamic WS URL instead of a static custom domain)

devlsh avatar Sep 21 '21 11:09 devlsh

I can't think of a reason why we would want to attempt to message on a socket via an API that isn't the one that established the connection - do you have any more info on why you might want to do this?

@andyrichardson @oyed In my case, when developing on a local environment (localhost), API Gateway posts a message using the 443 port instead of my port (which is 3001 in my case right now) on which my localhost environment is running on. Would be nice to have a way to set the endpoint host and/or port manually so it can work in this scenario.

As a test, I manually edited the node_modules files of subscriptionless to make it work by adding the "http" and my port but then I get another error:

Error [UnknownError]: Not Found
    at Object.extractError (.\node_modules\aws-sdk\lib\protocol\json.js:52:27)
    at Request.extractError (.\node_modules\aws-sdk\lib\protocol\rest_json.js:49:8)
    at Request.callListeners (.\node_modules\aws-sdk\lib\sequential_executor.js:106:20)
    at Request.emit (.\node_modules\aws-sdk\lib\sequential_executor.js:78:10)
    at Request.emit (.\node_modules\aws-sdk\lib\request.js:686:14)
    at Request.transition (.\node_modules\aws-sdk\lib\request.js:22:10)
    at AcceptorStateMachine.runTo (.\node_modules\aws-sdk\lib\state_machine.js:14:12)

Out of curiosity, how do you work with this library locally @andyrichardson ?

IonelLupu avatar Nov 21 '21 17:11 IonelLupu

A little late to this but to answer your question - the majority of my time has been working on this in a deployed environment.

Out of curiousity, what values is your development setup (serverless framework I'm guessing) giving you for the domain name here?

andyrichardson avatar Feb 17 '22 17:02 andyrichardson

hey @andyrichardson unfortunately I don't work on that project anymore and I don't have access to it 😞

IonelLupu avatar Feb 17 '22 21:02 IonelLupu

@andyrichardson I use a custom solution locally, combined with lambda-local, though for me the most "enticing" idea here is a custom domain for the WebSocket APIG

devlsh avatar Feb 18 '22 04:02 devlsh

unfortunately I don't work on that project anymore and I don't have access to it disappointed

@IonelLupu no worries :+1:

I use a custom solution locally

@oyed I'd be curious to see what you're cooking up! I need to invest some time looking into this because - as I mentioned - I haven't worked much with the local development tooling for mocking APIGateway.

The main thing I'm not quite understanding is why the tooling wouldn't set the domainName on the event to correspond to the mocked endpoint.

In the meantime, you could try this and let me know if it solves your issue.

andyrichardson avatar Feb 21 '22 11:02 andyrichardson