mirror of
https://github.com/xtr-dev/rondevu-server.git
synced 2025-12-14 12:53:23 +00:00
feat: Implement content-based offer IDs with SHA-256 hashing
- Added hash-id.ts utility for SHA-256 content hashing
- Offer IDs now generated from hash of {sdp, topics} (sorted)
- Removed peerId from hash (inferred from authentication)
- Server generates deterministic IDs for idempotent offer creation
- Updated SQLite and D1 storage implementations
- Removed optional id field from CreateOfferRequest
- Same offer content always produces same ID
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
51
src/config.ts
Normal file
51
src/config.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { generateSecretKey } from './crypto.ts';
|
||||
|
||||
/**
|
||||
* Application configuration
|
||||
* Reads from environment variables with sensible defaults
|
||||
*/
|
||||
export interface Config {
|
||||
port: number;
|
||||
storageType: 'sqlite' | 'memory';
|
||||
storagePath: string;
|
||||
corsOrigins: string[];
|
||||
version: string;
|
||||
authSecret: string;
|
||||
offerDefaultTtl: number;
|
||||
offerMaxTtl: number;
|
||||
offerMinTtl: number;
|
||||
cleanupInterval: number;
|
||||
maxOffersPerRequest: number;
|
||||
maxTopicsPerOffer: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads configuration from environment variables
|
||||
*/
|
||||
export function loadConfig(): Config {
|
||||
// Generate or load auth secret
|
||||
let authSecret = process.env.AUTH_SECRET;
|
||||
if (!authSecret) {
|
||||
authSecret = generateSecretKey();
|
||||
console.warn('WARNING: No AUTH_SECRET provided. Generated temporary secret:', authSecret);
|
||||
console.warn('All peer credentials will be invalidated on server restart.');
|
||||
console.warn('Set AUTH_SECRET environment variable to persist credentials across restarts.');
|
||||
}
|
||||
|
||||
return {
|
||||
port: parseInt(process.env.PORT || '3000', 10),
|
||||
storageType: (process.env.STORAGE_TYPE || 'sqlite') as 'sqlite' | 'memory',
|
||||
storagePath: process.env.STORAGE_PATH || ':memory:',
|
||||
corsOrigins: process.env.CORS_ORIGINS
|
||||
? process.env.CORS_ORIGINS.split(',').map(o => o.trim())
|
||||
: ['*'],
|
||||
version: process.env.VERSION || 'unknown',
|
||||
authSecret,
|
||||
offerDefaultTtl: parseInt(process.env.OFFER_DEFAULT_TTL || '60000', 10),
|
||||
offerMaxTtl: parseInt(process.env.OFFER_MAX_TTL || '86400000', 10),
|
||||
offerMinTtl: parseInt(process.env.OFFER_MIN_TTL || '60000', 10),
|
||||
cleanupInterval: parseInt(process.env.CLEANUP_INTERVAL || '60000', 10),
|
||||
maxOffersPerRequest: parseInt(process.env.MAX_OFFERS_PER_REQUEST || '100', 10),
|
||||
maxTopicsPerOffer: parseInt(process.env.MAX_TOPICS_PER_OFFER || '50', 10),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user