Skip to content

Commit

Permalink
fix frontend port in cors configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
hoeppner-dataport committed May 3, 2024
1 parent 0175083 commit f0c2c09
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion apps/server/src/apps/board-collaboration.app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async function bootstrap() {
await nestApp.init();

const port = 4450;
const basePath = '/api/v3';
const basePath = '/board-collaboration';

nestApp.setGlobalPrefix(basePath);
await nestApp.listen(port);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Configuration } from '@hpi-schul-cloud/commons/lib';

const host = Configuration.get('HOST') as string;
const isLocalhost = host.includes('localhost');
const origin = isLocalhost ? 'http://localhost:4000' : host;

export default class BoardCollaborationConfiguration {
static websocket = {
path: '/board-collaboration',
cors: {
origin,
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
preflightContinue: false,
optionsSuccessStatus: 204,
credentials: true,
},
};
}
14 changes: 2 additions & 12 deletions apps/server/src/modules/board/gateway/socket.gateway.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Configuration } from '@hpi-schul-cloud/commons/lib';
import { MikroORM, UseRequestContext } from '@mikro-orm/core';
import { UseGuards } from '@nestjs/common';
import { SubscribeMessage, WebSocketGateway, WsException } from '@nestjs/websockets';
Expand All @@ -13,6 +12,7 @@ import {
MoveCardMessageParams,
UpdateColumnTitleMessageParams,
} from './dto';
import BoardCollaborationConfiguration from './dto/board-collaboration-config';
import { CreateColumnMessageParams } from './dto/create-column.message.param';
import { DeleteBoardMessageParams } from './dto/delete-board.message.param';
import { FetchBoardMessageParams } from './dto/fetch-board.message.param';
Expand All @@ -21,17 +21,7 @@ import { UpdateBoardTitleMessageParams } from './dto/update-board-title.message.
import { UpdateBoardVisibilityMessageParams } from './dto/update-board-visibility.message.param';
import { Socket } from './types';

@WebSocketGateway({
path: '/board-collaboration',
cors: {
origin: `${(Configuration.get('HOST') as string) ?? 'http://localhost'}`.replace(/:\d+$/, ':4000'),
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
preflightContinue: false,
optionsSuccessStatus: 204,
credentials: true,
// transports: ['websocket'],
},
})
@WebSocketGateway(BoardCollaborationConfiguration.websocket)
@UseGuards(WsJwtAuthGuard)
export class SocketGateway {
// TODO: use loggables instead of legacy logger
Expand Down

0 comments on commit f0c2c09

Please sign in to comment.