Exports an async function that deploys the DynamoDB database
- Source:
(require("deployPollingRoute"))(restApiId, region, apiGatewayName, dynamoName, roleArn, bucketObjectTld, stageName, protectUrl) → {String}
- Source:
Exports deployPollingRoute()
Parameters:
Name | Type | Description |
---|---|---|
restApiId |
String | The id referring to the API Gateway |
region |
String | A constant destructured from the CLI user's answers in |
apiGatewayName |
String | A constant created in |
dynamoName |
String | Constant initialized in |
roleArn |
String | Amazon resource number for the kitchen sink role returned by |
bucketObjectTld |
String | A public URL where the object in the S3 bucket is located, i.e. the waiting room URL. |
stageName |
String | A constant "prod" |
protectUrl |
String | A constant destructured from the CLI user's answers in |
Returns:
A URL that the waiting room can poll to see if the user's token is in the DB https://${restApiId}.execute-api.${region}.amazonaws.com/${stageName}/${pollingResourceName}
;
- Type
- String
Methods
(async, inner) createResource(apiGateway, restApiId, resourceParentId, resourceName) → {String}
- Source:
Creates a subresource "/polling" of root
Parameters:
Name | Type | Description |
---|---|---|
apiGateway |
APIGatewayClient | Looks like |
restApiId |
String | The string returned from |
resourceParentId |
String | The id of the root resource returned from |
resourceName |
String | A constant "polling" |
Returns:
A resourceId referring to this new resource
- Type
- String
(async, inner) getResources(apiGateway, restApiId, apiGatewayName) → {String}
- Source:
Function which gets the id of the root resource "/" of the API Gateway originally created in deployApiGateway()
Parameters:
Name | Type | Description |
---|---|---|
apiGateway |
APIGatewayClient | Looks like |
restApiId |
String | ID refering to the API Gateway. Was returned from |
apiGatewayName |
String | A constant from |
Returns:
An id which refers to the root resource of the API Gateway, i.e. "/"
- Type
- String
(async, inner) putMethodRequest(apiGateway, restApiId, pollingResourceId, pollingResourceName)
- Source:
Our "/polling" endpoint has one method it handles, a GET request. This function creates it and customizes a header for the request named cookie
with a placeholder value of false at creation time.
Parameters:
Name | Type | Description |
---|---|---|
apiGateway |
APIGatewayClient | Looks like new |
restApiId |
String | The string returned from |
pollingResourceId |
String | Id referring to the "/polling" resource returned from |
pollingResourceName |
String | A constant "polling" |
(async, inner) setIntegrationRequest(apiGateway, pollingResourceId, restApiId, dynamoDbUri, pollingResourceName, roleArn, dynamoName)
- Source:
Instead of triggering a Lambda, this resource uses a template to access the cookie
value off the request headers and then performs a direct query of the DB to see if the token exists.
Parameters:
Name | Type | Description |
---|---|---|
apiGateway |
APIGatewayClient | Looks like |
pollingResourceId |
String | Id referring to the the "/polling" resource we created. |
restApiId |
String | The string returned from |
dynamoDbUri |
String | Uri that references the DynamoDB |
pollingResourceName |
String | Constant is "polling" |
roleArn |
String | Amazon resource number for the kitchen sink role returned by |
dynamoName |
String | Constant initialized in |
(async, inner) setIntegrationResponse(apiGateway, pollingResourceId, restApiId, pollingResourceName, bucketObjectTld, protectUrl)
- Source:
Creates the Integration Response stage of the API Gateway and makes customizations. We add specific headers to the response to allow CORS and since credentials are being sent with the original request to this resource, we have to specifically interpolate the URL we want the browswer to allow for Access-Control-Allow-Origin, in this case the waiting room URL. We also use a template to take the response from the DB and construct an object to send back to the client with two properties "allow" that will be a boolean and "protectUrl" that will be the final destination to redirect users to.
Parameters:
Name | Type | Description |
---|---|---|
apiGateway |
APIGatewayClient | Looks like |
pollingResourceId |
String | Id referring to the the "/polling" resource we created. |
restApiId |
String | The string returned from |
pollingResourceName |
String | Constant is "polling" |
bucketObjectTld |
String | A public URL where the object in the S3 bucket is located, i.e. the waiting room URL. |
protectUrl |
String | A constant destructured from the CLI user's answers in |
(async, inner) setMethodResponse(apiGateway, pollingResourceId, restApiId, pollingResourceName)
- Source:
Creates the Method Response stage. Of note is the creation of headers for CORS purposes. The values start out as false when creating them, but are changed in setIntegrationResponse()
Parameters:
Name | Type | Description |
---|---|---|
apiGateway |
APIGatewayClient | Looks like |
pollingResourceId |
String | Id referring to the the "/polling" resource we created. |
restApiId |
String | The string returned from |
pollingResourceName |
String | Constant is "polling" |