Skip to content

Commit 9c91861

Browse files
committed
fix: workspace url에 강제 접속할 때 소켓 서버 터지는 이슈 해결
1 parent cbb59b3 commit 9c91861

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

apps/backend/src/page/page.service.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,10 @@ export class PageService {
3535
*/
3636
async createPage(dto: CreatePageDto): Promise<Page> {
3737
const { title, content, workspaceId, x, y, emoji } = dto;
38-
3938
// 워크스페이스 DB에서 해당 워크스페이스의 내부 id를 찾는다
4039
const workspace = await this.workspaceRepository.findOneBy({
4140
snowflakeId: workspaceId,
4241
});
43-
4442
if (!workspace) {
4543
throw new WorkspaceNotFoundException();
4644
}

apps/websocket/src/yjs/yjs.service.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ export class YjsService
130130
const edgeResponse = await axios.get(
131131
`http://backend:3000/api/edge/workspace/${workspaceId}`,
132132
);
133+
134+
if (nodeResponse.status === 404 || edgeResponse.status === 404) {
135+
this.logger.error('워크 스페이스가 존재하지 않습니다.');
136+
return;
137+
}
133138
const edges = edgeResponse.data.edges;
134139

135140
const nodesMap = doc.getMap('nodes');
@@ -258,6 +263,19 @@ export class YjsService
258263
) {
259264
for (const [key, change] of event.changes.keys) {
260265
// TODO: change.action이 'add', 'delete'일 때 처리를 추가하여 REST API 사용 제거
266+
if (change.action === 'add') {
267+
const node = nodesMap.get(key);
268+
const { title, id, emoji } = node.data;
269+
const { x, y } = node.position;
270+
axios.post('http://backend:3000/api/page', {
271+
title,
272+
content,
273+
workspaceId,
274+
x,
275+
y,
276+
emoji,
277+
});
278+
}
261279
if (change.action !== 'update') continue;
262280

263281
const node: any = nodesMap.get(key);
@@ -272,6 +290,10 @@ export class YjsService
272290
const pageResponse = await axios.get(
273291
`http://backend:3000/api/page/${id}`,
274292
);
293+
if (pageResponse.status === 404) {
294+
this.logger.error('페이지가 존재하지 않습니다.');
295+
return;
296+
}
275297
const findPage = pageResponse.data.page;
276298

277299
await this.redisService.setField(`node:${findPage.node.id}`, 'x', x);

0 commit comments

Comments
 (0)