deployClientCheckRoute

Exports an async function that creates the "/client" resource with a GET method on it. This is the endpoint our users can hit to verify that one of their users hasn't skipped the waiting room. That request from the final destination to here will have the cookie, which has the token. This endpoint takes that token and checks the DB to see if it is there.

Source:

(require("deployClientCheckRoute"))(restApiId, region, apiGatewayName, dynamoName, roleArn, stageName, protectUrl) → {String}

Source:

Exports deployClientCheckRoute()

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 deploy.js. Like "us-east-2".

apiGatewayName String

A constant created in deploy.js, is beekeeper-${PROFILE_NAME}-apigateway

dynamoName String

Constant initialized in deploy.js, looks like beekeeper-${PROFILE_NAME}-ddb

roleArn String

Amazon resource number for the kitchen sink role returned by createRole()

stageName String

A constant "prod"

protectUrl String

A constant destructured from the CLI user's answers in deploy.js. Like "https://www.example.com".

Returns:

A URL that the final destination can use to check that a given user didn't skip the waiting room, looks like https://${restApiId}.execute-api.${region}.amazonaws.com/${stageName}/${clientCheckResourceName};

Type
String

Methods

(async, inner) createResource(apiGateway, restApiId, resourceParentId, resourceName) → {String}

Source:

Creates a subresource "/client" of root

Parameters:
Name Type Description
apiGateway APIGatewayClient

Looks like new APIGatewayClient({ region })

restApiId String

The string returned from createApiGateway()

resourceParentId String

The id of the root resource returned from getResources();

resourceName String

A constant "client"

Returns:

A resourceId referring to this new resource

Type
String

(async, inner) deployResource(apiGateway, restApiId, stageName)

Source:

Now that the API Gateway was created and all resources and their methods are added, we deploy the API Gateway.

Parameters:
Name Type Description
apiGateway APIGatewayClient

Looks like new APIGatewayClient({ region })

restApiId String

The string returned from createApiGateway()

stageName String

A constant "prod"

(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 new APIGatewayClient({ region });

restApiId String

ID refering to the API Gateway. Was returned from deployApiGateway()

apiGatewayName String

A constant from deploy.js, looks like beekeeper-${PROFILE_NAME}-apigateway

Returns:

An id which refers to the root resource of the API Gateway, i.e. "/"

Type
String

(async, inner) putMethodRequest(apiGateway, restApiId, clientCheckResourceId, clientCheckResourceName)

Source:

Our "/client" endpoint has one method it handles, a GET request. This function creates it and customizes a header for the request named cookie so that it can be grabbed off the request at the next stage.

Parameters:
Name Type Description
apiGateway APIGatewayClient

Looks like new APIGatewayClient({ region })

restApiId String

The string returned from createApiGateway()

clientCheckResourceId String

Id referring to the "/client" resource returned from createResource()

clientCheckResourceName String

A constant "client"

(async, inner) setIntegrationRequest(apiGateway, clientCheckResourceId, restApiId, dynamoDbUri, clientCheckResourceName, 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 new APIGatewayClient({ region })

clientCheckResourceId String

Id referring to the the "/client" resource we created.

restApiId String

The string returned from createApiGateway()

dynamoDbUri String

Uri that references the DynamoDB

clientCheckResourceName String

Constant is "client"

roleArn String

Amazon resource number for the kitchen sink role returned by createRole()

dynamoName String

Constant initialized in deploy.js, looks like beekeeper-${PROFILE_NAME}-ddb

(async, inner) setIntegrationResponse(apiGateway, clientCheckResourceId, restApiId, clientCheckResourceName, 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. We also use a template to take the response from the DB and construct an object to send back to the client with one property "allow" that will be a boolean.

Parameters:
Name Type Description
apiGateway APIGatewayClient

Looks like new APIGatewayClient({ region })

clientCheckResourceId String

Id referring to the the "/client" resource we created.

restApiId String

The string returned from createApiGateway()

clientCheckResourceName String

Constant is "client"

protectUrl String

A constant destructured from the CLI user's answers in deploy.js. Like "https://www.example.com".

(async, inner) setMethodResponse(apiGateway, clientCheckResourceId, restApiId, clientCheckResourceName)

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 new APIGatewayClient({ region })

clientCheckResourceId String

Id referring to the the "/client" resource we created.

restApiId String

The string returned from createApiGateway()

clientCheckResourceName String

Constant is "client"