diff --git a/api/package.json b/api/package.json index 91511e0..116c59c 100644 --- a/api/package.json +++ b/api/package.json @@ -30,7 +30,7 @@ "@nestjs/core": "^10.0.0", "@nestjs/passport": "^10.0.3", "@nestjs/platform-express": "^10.0.0", - "@noahspan/noahspan-modules": "^0.3.9", + "@noahspan/noahspan-modules": "^0.4.0", "@schematics/angular": "^17.3.7", "dotenv": "^16.4.5", "reflect-metadata": "0.1.13", diff --git a/api/src/pilot/info/pilot-info.service.ts b/api/src/pilot/info/pilot-info.service.ts index e560678..1ece3ad 100644 --- a/api/src/pilot/info/pilot-info.service.ts +++ b/api/src/pilot/info/pilot-info.service.ts @@ -11,9 +11,9 @@ export class PilotInfoService { constructor(private readonly tableService: TableService) {} - // async find(rowKey: string): Promise { - // return await this.pilotInfoRepository.find(this.partitionKey, rowKey); - // } + async find(rowKey: string): Promise { + return await this.pilotInfoRepository.find(this.partitionKey, rowKey); + } async findAll(): Promise { try { diff --git a/api/src/pilot/interceptors/pilot.interceptor.ts b/api/src/pilot/interceptors/pilot.interceptor.ts new file mode 100644 index 0000000..53b5d39 --- /dev/null +++ b/api/src/pilot/interceptors/pilot.interceptor.ts @@ -0,0 +1,16 @@ +import { CallHandler, ExecutionContext, NestInterceptor } from '@nestjs/common'; +import { Observable, map } from 'rxjs'; + +export class PilotInterceptor implements NestInterceptor { + intercept(context: ExecutionContext, handler: CallHandler): Observable { + const req = context.switchToHttp().getRequest(); + const authHeader = req.headers.authorization; + const token = authHeader && authHeader.split(' ')[1]; + + if (!token) { + return handler.handle().pipe(map((data) => data)); + } + + return handler.handle().pipe(map((data) => data)); + } +} diff --git a/api/src/pilot/pilot.controller.ts b/api/src/pilot/pilot.controller.ts index e2b8b9f..9d8e0d5 100644 --- a/api/src/pilot/pilot.controller.ts +++ b/api/src/pilot/pilot.controller.ts @@ -1,15 +1,26 @@ -import { Body, Controller, Get, HttpException, Post } from '@nestjs/common'; +import { + Body, + Controller, + Get, + HttpException, + Post, + UseInterceptors +} from '@nestjs/common'; import { PilotInfoService } from './info/pilot-info.service'; import { PilotInfoDto } from './info/pilot-info.dto'; import { TableInsertEntityHeaders } from '@azure/data-tables'; import { CustomError } from '../customError/CustomError'; import { PilotInfoEntity } from './info/pilot-info.entity'; +import { AuthInterceptor } from 'src/interceptors/auth.interceptor'; +import { Public } from '@noahspan/noahspan-modules'; @Controller('pilots') export class PilotController { constructor(private readonly pilotInfoService: PilotInfoService) {} @Get() + @Public() + @UseInterceptors(AuthInterceptor) async findAll(): Promise { try { const pilots: PilotInfoEntity[] = await this.pilotInfoService.findAll(); diff --git a/infrastructure/dns.tf b/infrastructure/dns.tf new file mode 100644 index 0000000..7a3be84 --- /dev/null +++ b/infrastructure/dns.tf @@ -0,0 +1,4 @@ +data "azurerm_dns_zone" "dns_zone" { + name = var.DOMAIN_NAME + resource_group_name = data.azurerm_resource_group.resource_group.name +} \ No newline at end of file diff --git a/infrastructure/main.tf b/infrastructure/main.tf index 1e4b366..a5537ee 100644 --- a/infrastructure/main.tf +++ b/infrastructure/main.tf @@ -1,9 +1,31 @@ -module "static_web_app" { - source = "github.com/noahspannbauer/noahspan-root/infrastructure/modules/static_web_app" - region = var.REGION - resource_group_name = data.azurerm_resource_group.resource_group.name - static_web_app_name = var.STATIC_WEB_APP_NAME - custom_domain_name_count = var.CUSTOM_DOMAIN_NAME_COUNT - domain_name = var.DOMAIN_NAME - subdomain_name = var.SUBDOMAIN_NAME +# module "static_web_app" { +# source = "github.com/noahspannbauer/noahspan-root/infrastructure/modules/static_web_app" +# region = var.REGION +# resource_group_name = data.azurerm_resource_group.resource_group.name +# static_web_app_name = var.STATIC_WEB_APP_NAME +# custom_domain_name_count = var.CUSTOM_DOMAIN_NAME_COUNT +# domain_name = var.DOMAIN_NAME +# subdomain_name = var.SUBDOMAIN_NAME +# } + +resource "azurerm_static_web_app" "static_web_app" { + name = var.STATIC_WEB_APP_NAME + resource_group_name = data.azurerm_resource_group.resource_group.name + location = var.REGION +} + +resource "azurerm_dns_cname_record" "dns_cname_record" { + name = var.SUBDOMAIN_NAME + zone_name = data.azurerm_dns_zone.dns_zone.name + resource_group_name = data.azurerm_resource_group.resource_group.name + ttl = 14400 + record = azurerm_static_web_app.static_web_app.default_host_name +} + +resource "azurerm_static_web_app_custom_domain" "static_web_app_custom_domain" { + static_web_app_id = azurerm_static_web_app.static_web_app.id + domain_name = "${var.SUBDOMAIN_NAME}.${var.DOMAIN_NAME}" + validation_type = "cname-delegation" + + depends_on = [ azurerm_dns_cname_record.dns_cname_record ] } \ No newline at end of file diff --git a/infrastructure/outputs.tf b/infrastructure/outputs.tf index c433ec7..5ec0493 100644 --- a/infrastructure/outputs.tf +++ b/infrastructure/outputs.tf @@ -1,8 +1,8 @@ output "api_key" { - value = module.static_web_app.api_key + value = azurerm_static_web_app.static_web_app.api_key sensitive = true } output "default_host_name" { - value = module.static_web_app.default_host_name + value = azurerm_static_web_app.static_web_app.default_host_name } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 5ff1e2b..db152e7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -40,7 +40,7 @@ "@nestjs/core": "^10.0.0", "@nestjs/passport": "^10.0.3", "@nestjs/platform-express": "^10.0.0", - "@noahspan/noahspan-modules": "^0.3.9", + "@noahspan/noahspan-modules": "^0.4.0", "@schematics/angular": "^17.3.7", "dotenv": "^16.4.5", "reflect-metadata": "0.1.13", @@ -3431,9 +3431,9 @@ } }, "node_modules/@noahspan/noahspan-modules": { - "version": "0.3.9", - "resolved": "https://registry.npmjs.org/@noahspan/noahspan-modules/-/noahspan-modules-0.3.9.tgz", - "integrity": "sha512-gRW+DiXQP+/0vHvEBi5yijQwwUnP+z5YxlSU7Q/bzm7YdUv5ecbZrz4is+BzH1S6Ctds9DeoQKtvb9xbAKwg8w==", + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/@noahspan/noahspan-modules/-/noahspan-modules-0.4.0.tgz", + "integrity": "sha512-oFOFL6AiEVlNmURAxDdnKg6xNZVZhQOPNeDtwWwbgYf2CQAHOapiBpKwHDAWT7DVpoBEurvmDEXeCHGl8mhGUw==", "dependencies": { "@azure/app-configuration": "^1.6.0", "@azure/data-tables": "^13.2.2",