From 5f0c67c3cf6635ff2bb5d01d4759a6e53f22647c Mon Sep 17 00:00:00 2001 From: Isaac Hunter Date: Sat, 25 Jan 2025 15:29:17 -0500 Subject: [PATCH] modify types, modify cors settings --- src/app.gateway.ts | 6 +++++- src/jukebox/jukebox.gateway.ts | 8 ++++++-- src/main.ts | 4 +++- src/types/README.md | 37 ++++++++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 src/types/README.md diff --git a/src/app.gateway.ts b/src/app.gateway.ts index f9c7ac4..74b1022 100644 --- a/src/app.gateway.ts +++ b/src/app.gateway.ts @@ -1,7 +1,11 @@ import { WebSocketGateway, WebSocketServer } from '@nestjs/websockets' import { Server } from 'socket.io' -@WebSocketGateway({ cors: true }) +@WebSocketGateway({ + cors: { + origin: '*', + }, +}) export class AppGateway { @WebSocketServer() server: Server } diff --git a/src/jukebox/jukebox.gateway.ts b/src/jukebox/jukebox.gateway.ts index 243e9f4..0a0d22c 100644 --- a/src/jukebox/jukebox.gateway.ts +++ b/src/jukebox/jukebox.gateway.ts @@ -3,11 +3,15 @@ import { Server, Socket } from 'socket.io' import { AppGateway } from 'src/app.gateway' import { SpotifyService } from 'src/spotify/spotify.service' import { PlayerMetaStateDto, PlayerStateActionDto } from './dto/player-state.dto' -import { PlayerAuxUpdateDto, PlayerUpdateDto } from './dto/track-player-state.dto' +import { PlayerAuxUpdateDto } from './dto/track-player-state.dto' import { JukeboxService } from './jukebox.service' import { TrackQueueService } from './track-queue/track-queue.service' -@WebSocketGateway() +@WebSocketGateway({ + cors: { + origin: '*', + }, +}) export class JukeboxGateway { constructor( private queueSvc: TrackQueueService, diff --git a/src/main.ts b/src/main.ts index 911600a..5b51134 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,4 +1,4 @@ -import { ValidationPipe } from '@nestjs/common' +import { Logger, ValidationPipe } from '@nestjs/common' import { NestFactory } from '@nestjs/core' import { SwaggerModule } from '@nestjs/swagger' import { AppModule } from './app.module' @@ -15,6 +15,8 @@ const bootstrap = async () => { app.enableCors({ origin: ['http://localhost:3000'], credentials: true }) const document = generateSwaggerDocument(app) + Logger.error("Starting app 1...") + SwaggerModule.setup('/api/docs/', app, document, { yamlDocumentUrl: '/api/v1/schema/jukebox/' }) diff --git a/src/types/README.md b/src/types/README.md new file mode 100644 index 0000000..3792e07 --- /dev/null +++ b/src/types/README.md @@ -0,0 +1,37 @@ +# Jukebox Types + +## Interface Standards + +All models have the following fields: + +```ts +// Default fields for all models +interface IModel { + id: string + created_at: string + updated_at: string +} +``` + +For a model `Example`, the following types would be: + +```ts +// Base object, has all fields from database +interface IExample extends IModel {} +// Fields used to create object +interface IExampleCreate extends ICreate {} +// Fields used to update object +interface IExampleUpdate extends IUpdate {} + +/** Optional Interfaces */ +// Aggregate related data for object +interface IExampleDetails extends IExample {} +``` + +## Conventions + +For a model `Example`, abide by the following: + +- Objects generated from ORMs or Schemas would be called `Example` +- Interfaces called `IExample` +- All fields in object are snake case, regardless of the tech stack used. This should be especially enforced in REST APIs.