Skip to content

Commit

Permalink
fix: query string parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Deivu committed Dec 22, 2024
1 parent adb8de2 commit 2b635e8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Indomitable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export class Indomitable extends EventEmitter {
const sessions = await this.fetchSessions();
this.concurrencyServer = new ConcurrencyServer(this, sessions.session_start_limit.max_concurrency);
const info = await this.concurrencyServer.start();
this.emit(LibraryEvents.DEBUG, `Handle concurrency is currently enabled! =>\nServer is currently bound to:\n Address: ${info.address}:${info.port}\n Concurrency: ${sessions.session_start_limit.max_concurrency}`);
this.emit(LibraryEvents.DEBUG, `Handle concurrency is currently enabled! =>\n Server is currently bound to:\n Address: ${info.address}:${info.port}\n Concurrency: ${sessions.session_start_limit.max_concurrency}`);
}
if (typeof this.clusterCount !== 'number')
this.clusterCount = Os.cpus().length;
Expand Down
11 changes: 5 additions & 6 deletions src/concurrency/ConcurrencyServer.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { AddressInfo } from 'node:net';
import { ConcurrencyManager } from './ConcurrencyManager';
import { Indomitable } from '../Indomitable';
import { LibraryEvents } from '../Util';
import Http from 'node:http';
import {LibraryEvents} from "../Util";
import QueryString from 'node:querystring';

/**
* Server that handles identify locks
*/
export class ConcurrencyServer {
private readonly manager: Indomitable;
/**
* Fastify instance of this server
* Http server of this instance
* @private
*/
private readonly server: Http.Server;
Expand Down Expand Up @@ -64,15 +65,13 @@ export class ConcurrencyServer {
return void response.end();
}

// @ts-expect-error: this is ok
if (!request.query.hasOwnProperty('shardId')) {
if (!request.url.includes('?shardId=')) {
response.statusCode = 400;
response.statusMessage = 'Bad Request';
return void response.end('Missing shardId query string');
}

// @ts-expect-error: this is ok
const shardId = Number(request.query['shardId']);
const shardId = Number(request.url.split('?shardId=')[1]);

if (isNaN(shardId)) {
response.statusCode = 400;
Expand Down

0 comments on commit 2b635e8

Please sign in to comment.