Skip to content

Commit

Permalink
fix: get ip from request meta
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-yarmosh committed Jul 12, 2024
1 parent 1de0278 commit eb14eb5
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
10 changes: 7 additions & 3 deletions src/alternative-ip/route/alternative-ip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ import { alternativeIps } from '../../lib/ws/server.js';

const handle = async (ctx: Context): Promise<void> => {
const request = ctx.request.body as AlternativeIpRequest;
await alternativeIps.validateTokenFromHttp(request);

ctx.body = {
};
await alternativeIps.validateTokenFromHttp({
socketId: request.socketId,
token: request.token,
ip: ctx.request.ip,
});

ctx.body = {};
};

export const registerAlternativeIpRoute = (router: Router): void => {
Expand Down
2 changes: 0 additions & 2 deletions src/alternative-ip/schema.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import Joi from 'joi';
import { globalIpOptions } from '../measurement/schema/utils.js';

export const schema = Joi.object({
socketId: Joi.string().length(20).required(),
ip: Joi.string().ip(globalIpOptions).required(),
token: Joi.string().uuid().required(),
});
1 change: 0 additions & 1 deletion src/alternative-ip/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export type AlternativeIpRequest = {
socketId: string;
ip: string;
token: string;
};
3 changes: 1 addition & 2 deletions src/lib/alternative-ips.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { randomUUID } from 'node:crypto';
import type { ServerSocket } from './ws/server.js';
import type { SyncedProbeList } from './ws/synced-probe-list.js';
import TTLCache from '@isaacs/ttlcache';
import type { AlternativeIpRequest } from '../alternative-ip/types.js';

const ALT_IP_MESSAGE_TYPE = 'alternative-ip';

Expand Down Expand Up @@ -30,7 +29,7 @@ export class AlternativeIps {
console.log('token', token);
}

async validateTokenFromHttp (request: AlternativeIpRequest) {
async validateTokenFromHttp (request: AltIpMessage['body']) {
const localSocket = this.tokenToSocket.get(request.token);

if (localSocket) {
Expand Down

0 comments on commit eb14eb5

Please sign in to comment.