Skip to content

Commit

Permalink
modify types, modify cors settings
Browse files Browse the repository at this point in the history
  • Loading branch information
IkeHunter committed Jan 25, 2025
1 parent 6f11b8b commit 5f0c67c
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/app.gateway.ts
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 6 additions & 2 deletions src/jukebox/jukebox.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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/' })

Expand Down
37 changes: 37 additions & 0 deletions src/types/README.md
Original file line number Diff line number Diff line change
@@ -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<IExample> {}
// Fields used to update object
interface IExampleUpdate extends IUpdate<IExample> {}

/** 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.

0 comments on commit 5f0c67c

Please sign in to comment.