Skip to content

Commit

Permalink
Merge pull request #212 from jonfairbanks/feat/typescript
Browse files Browse the repository at this point in the history
Migrate Yo to Typescript
  • Loading branch information
jonfairbanks authored Oct 12, 2024
2 parents 8416fb8 + e5e91c7 commit b122328
Show file tree
Hide file tree
Showing 26 changed files with 5,032 additions and 619 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ jobs:
strategy:
fail-fast: false
matrix:
language: [ 'javascript' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
language: [ 'javascript-typescript' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript-typescript', 'python' ]
# Learn more:
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -50,7 +50,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -64,4 +64,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v2
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ server/yo.log
/server/dist
.tf/.terraform/providers/registry.terraform.io/hashicorp/aws/5.70.0/darwin_arm64/terraform-provider-aws_v5.70.0_x5
.tf/.terraform/providers/registry.terraform.io/hashicorp/aws/5.70.0/darwin_arm64/LICENSE.txt
server/.env.production
server/.env.development
38 changes: 7 additions & 31 deletions .tf/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ terraform {

provider "aws" {
region = "us-east-1"
default_tags {
tags = {
environment = var.environment
service = "yo-api"
}
}
}

/* ------------------------- */
Expand All @@ -40,11 +46,6 @@ resource "aws_iam_role" "yo_api_lambda_role" {
}
]
})

tags = {
environment = var.environment
service = "yo-api"
}
}

/* ------------------------- */
Expand All @@ -67,11 +68,6 @@ resource "aws_lambda_function" "yo_api_lambda" {
ENV_VAR_NAME = "value"
}
}

tags = {
environment = var.environment
service = "yo-api"
}
}

# resource "aws_lambda_function_url" "yo_api_lambda_function_url" {
Expand All @@ -89,11 +85,6 @@ resource "aws_lambda_function" "yo_api_lambda" {
resource "aws_cloudwatch_log_group" "yo_api_loggroup" {
name = "/aws/lambda/${aws_lambda_function.yo_api_lambda.function_name}"
retention_in_days = 3

tags = {
environment = var.environment
service = "yo-api"
}
}

data "aws_iam_policy_document" "yo_api_lambda_policy" {
Expand Down Expand Up @@ -132,11 +123,6 @@ data "aws_acm_certificate" "issued" {
resource "aws_api_gateway_rest_api" "yo_api" {
name = "yo-api-${var.environment}"
description = "API Gateway for yo-api-${var.environment}"

tags = {
environment = var.environment
service = "yo-api"
}
}

/* ------------------------- */
Expand Down Expand Up @@ -266,11 +252,6 @@ resource "aws_api_gateway_method_settings" "yo_api_settings" {
resource "aws_cloudwatch_log_group" "yo_api_gw_logs" {
name = "/aws/apigateway/${aws_api_gateway_rest_api.yo_api.id}/${var.environment}"
retention_in_days = 3

tags = {
environment = var.environment
service = "yo-api"
}
}

resource "aws_cloudwatch_log_group" "yo_api_gw_loggroup" {
Expand Down Expand Up @@ -309,11 +290,6 @@ resource "aws_iam_role" "api_gateway_logging_role" {
}
]
})

tags = {
environment = var.environment
service = "yo-api"
}
}

resource "aws_iam_role_policy_attachment" "api_gateway_logging_policy" {
Expand Down Expand Up @@ -392,5 +368,5 @@ output "cloudwatch_log_group" {

output "route53_record" {
description = "The Route 53 DNS record"
value = aws_route53_record.yo_api_cname.fqdn
value = "https://${aws_route53_record.yo_api_cname.fqdn}"
}
4 changes: 4 additions & 0 deletions server/.env.development.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
MONGO_URI=mongodb://localhost:27017/yo
ERROR_URL=https://yo.mysite.dev/error
BASE_URL=https://yo.mysite.dev
API_URL=https://yo-api.mysite.dev/api/
4 changes: 4 additions & 0 deletions server/.env.production.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
MONGO_URI=mongodb://localhost:27017/yo
ERROR_URL=https://yo.mysite.io/error
BASE_URL=https://yo.mysite.io
API_URL=https://yo-api.mysite.io/api/
6 changes: 3 additions & 3 deletions server/.env.sample
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ERROR_URL=https://yo.mysite.io/error
BASE_URL=https://yo.mysite.io
API_URL=https://yo-api.mysite.io/api/
AUTH=false
AUTH0_DOMAIN=fairbanks.auth0.com
LOG_LOCATION=./yo-api.log
107 changes: 107 additions & 0 deletions server/.serverless/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
{
"/Users/jonfairbanks/Documents/GitHub/yo/server": {
"versionSfCore": null,
"versionFramework": "4.4.5",
"isWithinCompose": false,
"isCompose": false,
"composeOrgName": null,
"composeResolverProviders": {
"default-aws-credential-resolver": "<REDACTED>"
},
"composeServiceName": null,
"servicePath": "/Users/jonfairbanks/Documents/GitHub/yo/server",
"serviceConfigFileName": "serverless.yml",
"service": {
"service": "yo-api-lambda",
"provider": {
"name": "aws",
"runtime": "nodejs18.x",
"environment": {
"NODE_ENV": "dev",
"MONGO_URI": "mongodb+srv://yodawg:5v4wBu71I2zxGSne@fairbanks-io.mydxp.azure.mongodb.net/yo?retryWrites=true&w=majority"
},
"stage": "dev",
"region": "us-east-1",
"versionFunctions": true
},
"plugins": [
"serverless-offline"
],
"functions": {
"app": {
"handler": "src/index.handler",
"events": [
{
"http": {
"path": "/",
"method": "get"
}
},
{
"http": {
"path": {
"proxy+": null
},
"method": "any"
}
}
],
"name": "yo-api-lambda-dev-app"
}
},
"custom": {
"serverless-offline": {
"port": 3000,
"host": "localhost",
"babelOptions": {
"presets": [
"env"
]
}
}
}
},
"serviceRawFile": "service: yo-api-lambda\n\nprovider:\n name: aws\n runtime: nodejs18.x\n environment:\n NODE_ENV: dev\n MONGO_URI: mongodb+srv://yodawg:5v4wBu71I2zxGSne@fairbanks-io.mydxp.azure.mongodb.net/yo?retryWrites=true&w=majority\n\nplugins:\n - serverless-offline\n\nfunctions:\n app:\n handler: src/index.handler\n events:\n - http:\n path: /\n method: get\n - http:\n path: {proxy+}\n method: any\n\ncustom:\n serverless-offline:\n port: 3000\n host: localhost\n babelOptions:\n presets: [\"env\"]",
"command": [
"offline",
"start"
],
"options": {},
"error": {
"message": "path.startsWith is not a function",
"stack": "TypeError: path.startsWith is not a function\n at generateHapiPath (file:///Users/jonfairbanks/Documents/GitHub/yo/server/node_modules/serverless-offline/src/utils/generateHapiPath.js:2:23)\n at HttpServer.createRoutes (file:///Users/jonfairbanks/Documents/GitHub/yo/server/node_modules/serverless-offline/src/events/http/HttpServer.js:997:18)\n at #createEvent (file:///Users/jonfairbanks/Documents/GitHub/yo/server/node_modules/serverless-offline/src/events/http/Http.js:41:22)\n at file:///Users/jonfairbanks/Documents/GitHub/yo/server/node_modules/serverless-offline/src/events/http/Http.js:46:24\n at Array.forEach (<anonymous>)\n at Http.create (file:///Users/jonfairbanks/Documents/GitHub/yo/server/node_modules/serverless-offline/src/events/http/Http.js:45:12)\n at #createHttp (file:///Users/jonfairbanks/Documents/GitHub/yo/server/node_modules/serverless-offline/src/ServerlessOffline.js:201:16)\n at async Promise.all (index 0)\n at async ServerlessOffline.start (file:///Users/jonfairbanks/Documents/GitHub/yo/server/node_modules/serverless-offline/src/ServerlessOffline.js:107:5)\n at async PluginManager.runHooks (file:///Users/jonfairbanks/.serverless/releases/4.4.5/package/dist/sf-core.js:915:9311)"
},
"params": {},
"machineId": "207bbefc63916c681c033217f312cb0c",
"stage": "dev",
"accessKeyV2": "<REDACTED>",
"accessKeyV1": "<REDACTED>",
"orgId": "7d05998a-d7a6-4e07-a173-00b2d81140a3",
"orgName": "fairbanksio",
"userId": "R2c1qY1GnbzdKL68Wh",
"dashboard": {
"isEnabledForService": false,
"requiredAuthentication": false,
"orgFeaturesInUse": null,
"orgObservabilityIntegrations": null,
"serviceAppId": null,
"serviceProvider": null,
"instanceParameters": null
},
"userName": "fairbanksio",
"subscription": null,
"userEmail": "fairplay89@gmail.com",
"serviceProviderAwsRegion": "us-east-1",
"serviceProviderAwsCredentials": "<REDACTED>",
"serviceProviderAwsAccountId": "872515285419",
"projectType": "traditional",
"versionSf": "4.4.5",
"serviceProviderAwsCfStackName": "yo-api-lambda-dev",
"serviceUniqueId": null,
"serviceProviderAwsCfStackId": null,
"serviceProviderAwsCfStackCreated": null,
"serviceProviderAwsCfStackUpdated": null,
"serviceProviderAwsCfStackStatus": null,
"serviceProviderAwsCfStackOutputs": null
}
}
14 changes: 14 additions & 0 deletions server/controllers/yo.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Request, Response, NextFunction } from 'express';

declare module './yo' {
export const getYo: (req: Request, res: Response) => Promise<void>;
export const postYo: (req: Request, res: Response, next: NextFunction) => Promise<void>;
export const updateYo: (req: Request, res: Response) => Promise<void>;
export const deleteYo: (req: Request, res: Response) => Promise<void>;
export const getStats: (req: Request, res: Response) => Promise<void>;
export const getRecent: (req: Request, res: Response) => Promise<void>;
export const getPopular: (req: Request, res: Response) => Promise<void>;
export const getLatest: (req: Request, res: Response) => Promise<void>;
export const getAll: (req: Request, res: Response) => Promise<void>;
export const emitSocketUpdate: (req: Request) => Promise<void>;
}
Loading

0 comments on commit b122328

Please sign in to comment.