Skip to content
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

Move optional mocking behind flag #29

Merged
merged 9 commits into from
Jun 23, 2022
Merged

Conversation

shanejearley
Copy link
Contributor

Makes the basic setup unreliant on any externally-installed CLI tool and moves mocking behind a flag.

Basic setup
Run npm run dev from project root. Uses the AWS-deployed dev stage endpoints service endpoints by default in the Vue app, so no upfront config is necessary. This stage can be overridden in .env with STAGE variable.

Mocking setup
Install the SAM CLI on your machine and then run npm run dev --mock. Uses the local dev stage endpoints (which you may even prefer to override with prod to do things like reference production static resources (email templates, for example) and pass them into your local development for testing. SAM CLI can crawl our AWS CDK stacks to find and serve API Gateway endpoints. We pass in environment variables to the frontend development server (process.env.PUBLIC_MOCK, process.env.PUBLIC_{"api-name")_URL to switch to local endpoint URLs.

Wrote more about the setup in the README.md. More about the SAM/CDK mocking integration here, and our script using the CLI is here.

Lastly just moved AWS-deployed API endpoints behind our custom domain for clean reference based on the current environment's stage.

@shanejearley shanejearley requested a review from ccali11 June 20, 2022 16:16
@shanejearley shanejearley changed the title Add optional mocking behind flag Move optional mocking behind flag Jun 20, 2022
@shanejearley
Copy link
Contributor Author

Will need to make a few more changes for cleanup.

@shanejearley
Copy link
Contributor Author

Makes the basic setup unreliant on any externally-installed CLI tool and moves mocking behind a flag.

Basic setup Run npm run dev from project root. Uses the AWS-deployed dev stage endpoints service endpoints by default in the Vue app, so no upfront config is necessary. This stage can be overridden in .env with STAGE variable.

Mocking setup Install the SAM CLI on your machine and then run npm run dev --mock. Uses the local dev stage endpoints (which you may even prefer to override with prod to do things like reference production static resources (email templates, for example) and pass them into your local development for testing. SAM CLI can crawl our AWS CDK stacks to find and serve API Gateway endpoints. We pass in environment variables to the frontend development server (process.env.PUBLIC_MOCK, process.env.PUBLIC_{"api-name")_URL to switch to local endpoint URLs.

Just to clarify, "we pass in environment variables" should be "the script passes environment variables" as a result of the --mock flag. No additional config is necessary, although you can optionally override the current profile, stage, etc. in your local .env.

Wrote more about the setup in the README.md. More about the SAM/CDK mocking integration here, and our script using the CLI is here.

Lastly just moved AWS-deployed API endpoints behind our custom domain for clean reference based on the current environment's stage.

I will wait for you @ccali11 to pull down and try/confirm/tear-apart before merging.

@ccali11
Copy link
Contributor

ccali11 commented Jun 23, 2022

  • Last link in the comment on this PR is broken
  • Should note which version of the AWS CLI we're using (1 or 2) in README
  • In README, it may be worth letting developer know which backend resources / services are relevant (in this case, maybe not bc it appears it is just a signup form that will eventually be either replaced or outshined by other services / features)

Otherwise - dude - this is so clean and well done. Nothing to tear to shreds. I set it up and it worked perfectly for me, although I already had my aws user and SAM cli installed. May be worth having Hawyar take try to run it (purposely didn't tag him so that I don't bias his experience).

@ccali11
Copy link
Contributor

ccali11 commented Jun 23, 2022

Going to skim through your code now before approving.

Copy link
Contributor

@ccali11 ccali11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So nicely done, @shanejearley. Feel free to ignore my questions if it's more trouble than it's worth answering them. Otherwise down to review whenever. Everything built nicely and was able to use the form and receive an email.

*
* @returns {string} The base URL for the users API
*/
function getUsersBaseUrl(): string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the real deal.

@@ -13,8 +13,8 @@ declare module '*.vue' {
export default component
}

declare type SignupResponse = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this file autogenerated?

@@ -6,6 +6,9 @@ import '@/index.css'
import { createRouter, createWebHistory } from 'vue-router'
import routes from '~pages'

console.log('Creating app...', import.meta.env)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with this import.meta.env syntax. What is that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -1,69 +1,47 @@
<script lang="ts" setup>
import { ArrowRightIcon } from '@heroicons/vue/solid'
import { ref, onMounted } from 'vue'
import { ref, Ref } from 'vue'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice refactors / cleanup. Can you point me to where I can learn more about this syntax? (Ref = ref<HTMLDivElement>())

I take it that lines 9 and 10 are enabled with Ref and html tag attributes such as ref="successMessage" below.

@@ -1,14 +1,22 @@
#!/usr/bin/env node
import 'source-map-support/register'
import * as cdk from 'aws-cdk-lib'
import { pascalCase } from '@casimir/lib'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How long did it take to familiarize yourself with the SAM/CDK? This all looks great.

/**
* WebsiteStack class constructor.
*
* Shortest name: {@link (WebsiteStack:constructor)}
* Full name: {@link (WebsiteStack:constructor)}
*/
constructor(scope: Construct, id: string, props?: StackProps) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the difference between WebsiteStackProps and StackProps?

@@ -1,40 +1,43 @@
#!/bin/sh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you write all of these scripts in the scripts directory from scratch? V impressive.

@@ -5,7 +5,7 @@ import {
} from '@aws-sdk/client-pinpoint'
import { APIGatewayEvent } from 'aws-lambda'
import { pascalCase } from '@casimir/lib'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this @casimir/lib?

@@ -5,7 +5,7 @@ import {
} from '@aws-sdk/client-pinpoint'
import { APIGatewayEvent } from 'aws-lambda'
import { pascalCase } from '@casimir/lib'
import { SignupResponse } from '../env'
import { APIGatewayResponse } from '../env'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the need/rationale for this change?

body: {
message: 'pong'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I liked 'pong'

@shanejearley shanejearley merged commit b195793 into develop Jun 23, 2022
@shanejearley shanejearley deleted the enhancement/config-defaults branch June 23, 2022 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants