Skip to content

fix(backend): cors and logger middleware #122

fix(backend): cors and logger middleware

fix(backend): cors and logger middleware #122

Workflow file for this run

name: Workflow
on: [push]
env:
AWS_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: us-east-2
jobs:
ci:
name: CI
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "20.x"
- name: Setup pnpm
uses: pnpm/action-setup@v3
with:
version: 8
run_install: |
- recursive: true
- name: Format
run: pnpm run format:check
- name: Write frontend environment variables
run: printf "VITE_API_BASE_URL=%s\n" "${{ vars.VITE_API_BASE_URL }}" >> .env
working-directory: ./apps/frontend
- name: Write backend environment variables
run: |
printf "EXTERNAL_API_BASE_URL=%s\n" "${{ vars.API_FUNCTION_EXTERNAL_API_BASE_URL }}" >> .env
printf "RESTAURANT_SCRAPE_BASE_URL=%s\n" "${{ vars.API_FUNCTION_RESTAURANT_SCRAPE_BASE_URL }}" >> .env
printf "FLAVORS_SCRAPE_BASE_URL=%s\n" "${{ vars.API_FUNCTION_FLAVORS_SCRAPE_BASE_URL }}" >> .env
printf "FLAVOR_IMAGE_BASE_URL=%s\n" "${{ vars.API_FUNCTION_FLAVOR_IMAGE_BASE_URL }}" >> .env
printf "LOGO_SVG_URL=%s\n" "${{ vars.API_FUNCTION_LOGO_SVG_URL }}" >> .env
printf "CORS_ORIGIN=%s\n" "${{ vars.API_FUNCTION_CORS_ORIGIN }}" >> .env
working-directory: ./apps/backend
- name: Build
run: pnpm run build
- name: Lint
run: pnpm run lint
- name: Test
run: pnpm run test
cd:
name: CD
runs-on: ubuntu-22.04
needs: [ci]
env:
TF_VAR_root_domain_name: ${{ vars.ROOT_DOMAIN_NAME }}
TF_VAR_cloudflare_api_token: ${{ secrets.TERRAFORM_CLOUDFLARE_API_TOKEN }}
TF_VAR_cloudflare_zone_id: ${{ secrets.TERRAFORM_CLOUDFLARE_ZONE_ID }}
TF_VAR_api_function_external_api_base_url: ${{ vars.API_FUNCTION_EXTERNAL_API_BASE_URL }}
TF_VAR_api_function_restaurant_scrape_base_url: ${{ vars.API_FUNCTION_RESTAURANT_SCRAPE_BASE_URL }}
TF_VAR_api_function_flavors_scrape_base_url: ${{ vars.API_FUNCTION_FLAVORS_SCRAPE_BASE_URL }}
TF_VAR_api_function_flavor_image_base_url: ${{ vars.API_FUNCTION_FLAVOR_IMAGE_BASE_URL }}
TF_VAR_api_function_logo_svg_url: ${{ vars.API_FUNCTION_LOGO_SVG_URL }}
TF_VAR_api_function_cors_origin: ${{ vars.API_FUNCTION_CORS_ORIGIN }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "20.x"
- name: Setup pnpm
uses: pnpm/action-setup@v3
with:
version: 8
run_install: |
- recursive: true
- name: Write frontend environment variables
run: printf "VITE_API_BASE_URL=%s\n" "${{ vars.VITE_API_BASE_URL }}" >> .env
working-directory: ./apps/frontend
- name: Build
run: pnpm run build
- name: Download LLRT
run: curl -L -o llrt.zip https://github.com/awslabs/llrt/releases/latest/download/llrt-lambda-arm64.zip
working-directory: ./apps/backend
- name: Unzip LLRT
run: unzip llrt.zip
working-directory: ./apps/backend
- name: Copy bootstrap
run: cp bootstrap ./lambda/
working-directory: ./apps/backend
- name: Zip lambda
run: pnpm run zip
working-directory: ./apps/backend
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
- name: Terraform Init
run: terraform init
working-directory: ./infra
- name: Terraform Validate
run: terraform validate
working-directory: ./infra
- name: Terraform Format
run: terraform fmt -check
working-directory: ./infra
- name: Terraform Plan
run: terraform plan -input=false
working-directory: ./infra
- name: Terraform Apply
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: terraform apply -auto-approve -input=false
working-directory: ./infra
- name: Download AWS CLI
if: ${{ env.ACT }}
run: curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
- name: Unzip AWS CLI
if: ${{ env.ACT }}
run: unzip -q awscliv2.zip
- name: Install AWS CLI
if: ${{ env.ACT }}
run: ./aws/install
- name: AWS CLI version
run: aws --version
- name: AWS CLI Configure
run: |
aws configure set aws_access_key_id $(echo $AWS_ACCESS_KEY)
aws configure set aws_secret_access_key $(echo $AWS_SECRET_ACCESS_KEY)
aws configure set region $(echo $AWS_REGION)
- name: Deploy
run: pnpm run deploy
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
env:
AWS_PAGER: ""