mirror of
https://git.meshkee.com/Meshkee/backend.git
synced 2026-08-12 06:40:58 +04:30
Serve public storefront docs at /docs/website, expose api.{domain} hosts for API SSL sync, and require push-then-pull deploys instead of rsync.
Co-authored-by: Cursor <cursoragent@cursor.com>
36 lines
1.0 KiB
TypeScript
36 lines
1.0 KiB
TypeScript
import {
|
|
CanActivate,
|
|
ExecutionContext,
|
|
Injectable,
|
|
UnauthorizedException,
|
|
} from '@nestjs/common';
|
|
import { ConfigService } from '@nestjs/config';
|
|
import { timingSafeEqual } from 'crypto';
|
|
import { Request } from 'express';
|
|
|
|
@Injectable()
|
|
export class SslSyncTokenGuard implements CanActivate {
|
|
constructor(private readonly config: ConfigService) {}
|
|
|
|
canActivate(context: ExecutionContext): boolean {
|
|
const expected = this.config.get<string>('SSL_SYNC_TOKEN')?.trim();
|
|
if (!expected) {
|
|
throw new UnauthorizedException('SSL sync is not configured');
|
|
}
|
|
|
|
const req = context.switchToHttp().getRequest<Request>();
|
|
const provided = String(req.headers['x-ssl-sync-token'] ?? '').trim();
|
|
if (!provided || provided.length !== expected.length) {
|
|
throw new UnauthorizedException('Invalid SSL sync token');
|
|
}
|
|
|
|
const a = Buffer.from(provided);
|
|
const b = Buffer.from(expected);
|
|
if (!timingSafeEqual(a, b)) {
|
|
throw new UnauthorizedException('Invalid SSL sync token');
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|