BREAKING CHANGE(project-structure): Refactor project structure by updating import paths, removing legacy files, and adjusting test configurations

This commit is contained in:
2025-05-09 21:52:46 +00:00
parent b214e58a26
commit 88c75d9cc2
20 changed files with 568 additions and 226 deletions

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@push.rocks/smartproxy',
version: '12.2.0',
version: '13.0.0',
description: 'A powerful proxy package that effectively handles high traffic, with features such as SSL/TLS support, port proxying, WebSocket handling, dynamic routing with authentication options, and automatic ACME certificate management.'
}

View File

@ -3,7 +3,7 @@ import * as path from 'path';
import type { AcmeOptions } from '../models/certificate-types.js';
import { ensureCertificateDirectory } from '../utils/certificate-helpers.js';
// We'll need to update this import when we move the Port80Handler
import { Port80Handler } from '../../port80handler/classes.port80handler.js';
import { Port80Handler } from '../../http/port80/port80-handler.js';
/**
* Factory to create a Port80Handler with common setup.

View File

@ -2,7 +2,7 @@ import * as plugins from '../../plugins.js';
import type { DomainConfig } from '../../forwarding/config/domain-config.js';
import type { CertificateData, DomainForwardConfig, DomainOptions } from '../models/certificate-types.js';
import { Port80HandlerEvents, CertProvisionerEvents } from '../events/certificate-events.js';
import { Port80Handler } from '../../port80handler/classes.port80handler.js';
import { Port80Handler } from '../../http/port80/port80-handler.js';
// We need to define this interface until we migrate NetworkProxyBridge
interface NetworkProxyBridge {
applyExternalCertificate(certData: CertificateData): void;

View File

@ -1,4 +1,4 @@
import type { Port80Handler } from '../port80handler/classes.port80handler.js';
import type { Port80Handler } from '../http/port80/port80-handler.js';
import { Port80HandlerEvents } from './types.js';
import type { ICertificateData, ICertificateFailure, ICertificateExpiring } from './types.js';

View File

@ -1,4 +1,4 @@
import type { Port80Handler } from '../../port80handler/classes.port80handler.js';
import type { Port80Handler } from '../../http/port80/port80-handler.js';
import { Port80HandlerEvents } from '../models/common-types.js';
import type { ICertificateData, ICertificateFailure, ICertificateExpiring } from '../models/common-types.js';

View File

@ -10,10 +10,14 @@ export * from './port80/index.js';
export * from './router/index.js';
export * from './redirects/index.js';
// Import the components we need for the namespace
import { Port80Handler } from './port80/port80-handler.js';
import { ChallengeResponder } from './port80/challenge-responder.js';
// Convenience namespace exports
export const Http = {
Port80: {
Handler: require('./port80/port80-handler.js').Port80Handler,
ChallengeResponder: require('./port80/challenge-responder.js').ChallengeResponder
Handler: Port80Handler,
ChallengeResponder: ChallengeResponder
}
};

View File

@ -5,15 +5,14 @@
// Legacy exports (to maintain backward compatibility)
// Migrated to the new proxies structure
export * from './proxies/nftables-proxy/index.js';
export * from './networkproxy/index.js';
export * from './proxies/network-proxy/index.js';
// Export port80handler elements selectively to avoid conflicts
export {
Port80Handler,
default as Port80HandlerDefault,
HttpError,
Port80HandlerError as HttpError,
ServerError,
CertificateError
} from './port80handler/classes.port80handler.js';
} from './http/port80/port80-handler.js';
// Use re-export to control the names
export { Port80HandlerEvents } from './certificate/events/certificate-events.js';

View File

@ -1,126 +0,0 @@
import * as plugins from '../plugins.js';
/**
* Configuration options for NetworkProxy
*/
import type { IAcmeOptions } from '../common/types.js';
/**
* Configuration options for NetworkProxy
*/
export interface INetworkProxyOptions {
port: number;
maxConnections?: number;
keepAliveTimeout?: number;
headersTimeout?: number;
logLevel?: 'error' | 'warn' | 'info' | 'debug';
cors?: {
allowOrigin?: string;
allowMethods?: string;
allowHeaders?: string;
maxAge?: number;
};
// Settings for PortProxy integration
connectionPoolSize?: number; // Maximum connections to maintain in the pool to each backend
portProxyIntegration?: boolean; // Flag to indicate this proxy is used by PortProxy
useExternalPort80Handler?: boolean; // Flag to indicate using external Port80Handler
// Protocol to use when proxying to backends: HTTP/1.x or HTTP/2
backendProtocol?: 'http1' | 'http2';
// ACME certificate management options
acme?: IAcmeOptions;
}
/**
* Interface for a certificate entry in the cache
*/
export interface ICertificateEntry {
key: string;
cert: string;
expires?: Date;
}
/**
* Interface for reverse proxy configuration
*/
export interface IReverseProxyConfig {
destinationIps: string[];
destinationPorts: number[];
hostName: string;
privateKey: string;
publicKey: string;
authentication?: {
type: 'Basic';
user: string;
pass: string;
};
rewriteHostHeader?: boolean;
/**
* Protocol to use when proxying to this backend: 'http1' or 'http2'.
* Overrides the global backendProtocol option if set.
*/
backendProtocol?: 'http1' | 'http2';
}
/**
* Interface for connection tracking in the pool
*/
export interface IConnectionEntry {
socket: plugins.net.Socket;
lastUsed: number;
isIdle: boolean;
}
/**
* WebSocket with heartbeat interface
*/
export interface IWebSocketWithHeartbeat extends plugins.wsDefault {
lastPong: number;
isAlive: boolean;
}
/**
* Logger interface for consistent logging across components
*/
export interface ILogger {
debug(message: string, data?: any): void;
info(message: string, data?: any): void;
warn(message: string, data?: any): void;
error(message: string, data?: any): void;
}
/**
* Creates a logger based on the specified log level
*/
export function createLogger(logLevel: string = 'info'): ILogger {
const logLevels = {
error: 0,
warn: 1,
info: 2,
debug: 3
};
return {
debug: (message: string, data?: any) => {
if (logLevels[logLevel] >= logLevels.debug) {
console.log(`[DEBUG] ${message}`, data || '');
}
},
info: (message: string, data?: any) => {
if (logLevels[logLevel] >= logLevels.info) {
console.log(`[INFO] ${message}`, data || '');
}
},
warn: (message: string, data?: any) => {
if (logLevels[logLevel] >= logLevels.warn) {
console.warn(`[WARN] ${message}`, data || '');
}
},
error: (message: string, data?: any) => {
if (logLevels[logLevel] >= logLevels.error) {
console.error(`[ERROR] ${message}`, data || '');
}
}
};
}

View File

@ -1,3 +0,0 @@
// Re-export all components from the new location
// This file is for backward compatibility only
export * from '../proxies/network-proxy/index.js';

View File

@ -1,24 +0,0 @@
/**
* TEMPORARY FILE FOR BACKWARD COMPATIBILITY
* This will be removed in a future version when all imports are updated
* @deprecated Use the new HTTP module instead
*/
// Re-export the Port80Handler from its new location
export * from '../http/port80/port80-handler.js';
// Re-export HTTP error types for backward compatibility
export * from '../http/models/http-types.js';
// Re-export selected events to avoid name conflicts
export {
CertificateEvents,
Port80HandlerEvents,
CertProvisionerEvents
} from '../certificate/events/certificate-events.js';
// Import the new Port80Handler
import { Port80Handler } from '../http/port80/port80-handler.js';
// Export it as the default export for backward compatibility
export default Port80Handler;

View File

@ -43,8 +43,9 @@ export class CertificateManager {
*/
public loadDefaultCertificates(): void {
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const certPath = path.join(__dirname, '..', '..', 'assets', 'certs');
// Fix the path to look for certificates at the project root instead of inside ts directory
const certPath = path.join(__dirname, '..', '..', '..', 'assets', 'certs');
try {
this.defaultCertificates = {
key: fs.readFileSync(path.join(certPath, 'key.pem'), 'utf8'),
@ -53,7 +54,7 @@ export class CertificateManager {
this.logger.info('Default certificates loaded successfully');
} catch (error) {
this.logger.error('Error loading default certificates', error);
// Generate self-signed fallback certificates
try {
// This is a placeholder for actual certificate generation code

View File

@ -1,15 +0,0 @@
# Legacy Notice
These files have been migrated to the new directory structure as part of the project restructuring. The new locations are as follows:
- `classes.smartproxy.ts` -> `/ts/proxies/smart-proxy/smart-proxy.ts`
- `classes.pp.connectionmanager.ts` -> `/ts/proxies/smart-proxy/connection-manager.ts`
- `classes.pp.securitymanager.ts` -> `/ts/proxies/smart-proxy/security-manager.ts`
- `classes.pp.domainconfigmanager.ts` -> `/ts/proxies/smart-proxy/domain-config-manager.ts`
- `classes.pp.tlsmanager.ts` -> `/ts/proxies/smart-proxy/tls-manager.ts`
- `classes.pp.networkproxybridge.ts` -> `/ts/proxies/smart-proxy/network-proxy-bridge.ts`
- `classes.pp.timeoutmanager.ts` -> `/ts/proxies/smart-proxy/timeout-manager.ts`
- `classes.pp.portrangemanager.ts` -> `/ts/proxies/smart-proxy/port-range-manager.ts`
- `classes.pp.connectionhandler.ts` -> `/ts/proxies/smart-proxy/connection-handler.ts`
This directory is now considered legacy and should not be used for new code.