File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed
Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change 11import { Middleware } from '@oak/oak' ;
22
3- const nodeId = crypto . randomUUID ( ) ;
3+ import { fromEnv } from '../utils/fromEnv.ts' ;
4+
5+ export const nodeId = crypto . randomUUID ( ) ;
6+
7+ export const inCluster = fromEnv ( 'CLUSTER' , {
8+ defaultValue : false ,
9+ allowDefaultValueInProd : true ,
10+ type : Boolean ,
11+ } ) ;
412
513export default function ( ) : Middleware {
614 return async ( ctx , next ) => {
Original file line number Diff line number Diff line change 99} from '../../../db/canvas.ts' ;
1010import { auth } from '../../../middleware/index.ts' ;
1111import { httpError } from '../../../utils/httpError.ts' ;
12+ import { inCluster , nodeId } from '../../../middleware/cluster.ts' ;
1213
1314const connections = new Set < WebSocket > ( ) ;
1415
@@ -36,6 +37,14 @@ function gateway(ctx: Context) {
3637
3738 ws . onopen = ( ) => {
3839 connections . add ( ws ) ;
40+
41+ if ( inCluster )
42+ ws . send (
43+ JSON . stringify ( {
44+ type : 'cluster' ,
45+ servedBy : nodeId ,
46+ } )
47+ ) ;
3948 } ;
4049
4150 ws . onmessage = async ( event ) => {
You can’t perform that action at this time.
0 commit comments