-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(be): separate socket server (#250)
* refactor: separate socket server * chore: auto-fix linting and formatting issues * fix: remove spec file --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
2a11f78
commit 226207a
Showing
17 changed files
with
152 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module.exports = { | ||
apps: [ | ||
{ | ||
name: 'http-server', | ||
script: 'pnpm', | ||
args: 'run start:prod', | ||
interpreter: 'none', | ||
cwd: './', | ||
env: { | ||
NODE_ENV: 'production', | ||
PORT: 3000, | ||
}, | ||
}, | ||
{ | ||
name: 'ws-server', | ||
script: 'pnpm', | ||
args: 'run start:prod', | ||
interpreter: 'none', | ||
cwd: './', | ||
env: { | ||
NODE_ENV: 'production', | ||
PORT: 4000, | ||
}, | ||
}, | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { BroadcastEventDto } from '@socket/dto/broadcast-event.dto'; | ||
|
||
const SOCKET_SERVER_HOST = process.env.SOCKET_SERVER_HOST; | ||
const SOCKET_SERVER_PORT = process.env.SOCKET_SERVER_PORT; | ||
|
||
export const requestSocket = async ({ event, content, sessionId, token }: BroadcastEventDto) => { | ||
try { | ||
await fetch(`${SOCKET_SERVER_HOST}:${SOCKET_SERVER_PORT}/api/socket/broadcast`, { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify({ | ||
event, | ||
content, | ||
sessionId, | ||
token, | ||
}), | ||
}); | ||
} catch (error) { | ||
throw error; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { IsNotEmpty } from 'class-validator'; | ||
|
||
import { BaseDto } from '@common/base.dto'; | ||
import { SOCKET_EVENTS } from '@socket/socket.constant'; | ||
|
||
export class BroadcastEventDto extends BaseDto { | ||
@IsNotEmpty({ message: '데이터는 필수입니다.' }) | ||
content: Record<any, any>; | ||
|
||
@IsNotEmpty({ message: '이벤트명은 필수입니다.' }) | ||
event: (typeof SOCKET_EVENTS)[keyof typeof SOCKET_EVENTS]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
export const SOCKET_EVENTS = { | ||
QUESTION_CREATED: 'questionCreated', | ||
QUESTION_UPDATED: 'questionUpdated', | ||
QUESTION_DELETED: 'questionDeleted', | ||
QUESTION_LIKED: 'questionLiked', | ||
|
||
REPLY_CREATED: 'replyCreated', | ||
REPLY_UPDATED: 'replyUpdated', | ||
REPLY_DELETED: 'replyDeleted', | ||
REPLY_LIKED: 'replyLiked', | ||
|
||
CREATE_CHAT: 'createChat', | ||
CHAT_MESSAGE: 'chatMessage', | ||
CHAT_ERROR: 'chatError', | ||
|
||
INVALID_CONNECTION: 'invalidConnection', | ||
DUPLICATED_CONNECTION: 'duplicatedConnection', | ||
PARTICIPANT_COUNT_UPDATED: 'participantCountUpdated', | ||
|
||
HOST_CHANGED: 'hostChanged', | ||
SESSION_ENDED: 'sessionEnded', | ||
} as const; |
Oops, something went wrong.