trying to stop proxy.js from exporting
This commit is contained in:
44
src/proxy.js
44
src/proxy.js
@@ -2,12 +2,14 @@
|
||||
* Google Drive Sitemap Adapter Proxy
|
||||
*
|
||||
* MONOLITHIC HTTP request handler - ALL functionality in this single file.
|
||||
* Architecture: Server.js delegates ALL requests to proxy.handleRequest(req, res)
|
||||
* Architecture: Server.js delegates ALL requests to this module's default function (req, res) => {}
|
||||
* Authentication: Service Account (JWT-based) inline
|
||||
*
|
||||
* CONSTITUTION REQUIREMENT: ZERO export statements - this file exports ONLY a default handler function
|
||||
*
|
||||
* Globals provided by server.js:
|
||||
* - console: Custom loggern
|
||||
* - crypto: Node.js crypto module (can't use 'crypto' - Web Crypto API conflict)
|
||||
* - console: Custom logger
|
||||
* - crypto: Web Crypto API (provides randomUUID())
|
||||
* - config: Infrastructure settings (server port, logging level)
|
||||
* - axios: HTTP client
|
||||
* - uuidv4: UUID generator
|
||||
@@ -683,7 +685,7 @@ async function handleSitemapRequest(res, requestId) {
|
||||
* @param {Object} req - HTTP request object
|
||||
* @param {Object} res - HTTP response object
|
||||
*/
|
||||
export async function handleRequest(req, res) {
|
||||
async function handleRequest(req, res) {
|
||||
const requestId = generateRequestId();
|
||||
const startTime = Date.now();
|
||||
|
||||
@@ -739,37 +741,5 @@ export async function handleRequest(req, res) {
|
||||
});
|
||||
}
|
||||
}
|
||||
handleRequest(req, res); // This line is just for clarity - actual invocation is done by server.js
|
||||
|
||||
// =============================================================================
|
||||
// Exports for Testing
|
||||
// =============================================================================
|
||||
|
||||
/**
|
||||
* Internal functions exported for unit testing only
|
||||
* DO NOT use these in production code - use handleRequest() instead
|
||||
*/
|
||||
export {
|
||||
// Authentication
|
||||
getAccessTokenCached,
|
||||
clearAuthCache,
|
||||
|
||||
// Utilities
|
||||
generateRequestId,
|
||||
validateDocumentId,
|
||||
escapeXml,
|
||||
|
||||
// Drive API Client
|
||||
DocumentCountExceededError,
|
||||
queryDocuments,
|
||||
mapDriveErrorToHttp,
|
||||
validateDocumentCount,
|
||||
|
||||
// Sitemap Generation
|
||||
toSitemapEntry,
|
||||
transformDocumentsToSitemapEntries,
|
||||
generateSitemapXML,
|
||||
generateSitemap,
|
||||
|
||||
// Request Queue
|
||||
requestQueue
|
||||
};
|
||||
|
||||
@@ -96,48 +96,6 @@ function validateConfig(config) {
|
||||
errors.push('Invalid server.port (must be 1-65535)');
|
||||
}
|
||||
|
||||
// Validate consolidated Google Drive settings from global
|
||||
const settings = globalThis['google_drive_settings'];
|
||||
if (!settings) {
|
||||
errors.push('Missing google_drive_settings in global/ directory (required for all functionality)');
|
||||
} else {
|
||||
// Validate service account
|
||||
if (!settings.serviceAccount) {
|
||||
errors.push('Missing serviceAccount in google_drive_settings');
|
||||
} else {
|
||||
if (!settings.serviceAccount.client_email || !settings.serviceAccount.private_key) {
|
||||
errors.push('Invalid serviceAccount format - missing client_email or private_key');
|
||||
}
|
||||
}
|
||||
|
||||
// Validate scopes (optional, will use default if missing)
|
||||
if (settings.scopes) {
|
||||
if (!Array.isArray(settings.scopes) || settings.scopes.length === 0) {
|
||||
errors.push('Invalid scopes (must be a non-empty array)');
|
||||
}
|
||||
} else {
|
||||
logger.warn('No scopes found in google_drive_settings - using default: ["https://www.googleapis.com/auth/drive.readonly"]');
|
||||
}
|
||||
|
||||
// Validate sitemap config (optional)
|
||||
if (settings.sitemap) {
|
||||
if (settings.sitemap.maxUrls && (settings.sitemap.maxUrls < 1 || settings.sitemap.maxUrls > 50000)) {
|
||||
errors.push('Invalid sitemap.maxUrls (must be 1-50000)');
|
||||
}
|
||||
} else {
|
||||
logger.warn('No sitemap config found in google_drive_settings - using default maxUrls: 50000');
|
||||
}
|
||||
|
||||
// Validate drive query (optional)
|
||||
if (settings.driveQuery) {
|
||||
if (typeof settings.driveQuery !== 'string') {
|
||||
errors.push('Invalid driveQuery (must be a string)');
|
||||
}
|
||||
} else {
|
||||
logger.warn('No driveQuery found in google_drive_settings - using default: "trashed = false"');
|
||||
}
|
||||
}
|
||||
|
||||
if (errors.length > 0) {
|
||||
throw new Error(`Configuration validation failed:\n${errors.join('\n')}`);
|
||||
}
|
||||
@@ -165,13 +123,17 @@ async function startServer() {
|
||||
validateConfig(global.config);
|
||||
logger.info('Configuration validated successfully');
|
||||
|
||||
// Import proxy after global.config is set
|
||||
const { handleRequest } = await import('./proxy.js');
|
||||
// Load proxy.js as a function wrapper (ZERO exports per constitution)
|
||||
// Import the module which sets up globalThis.handleRequest
|
||||
await import('./proxy.js');
|
||||
|
||||
// Wrap the global handleRequest function for clean invocation
|
||||
const handleRequest = (req, res) => {
|
||||
return globalThis.handleRequest(req, res);
|
||||
};
|
||||
|
||||
// Create HTTP server that delegates all requests to proxy
|
||||
const server = http.createServer((req, res) => {
|
||||
handleRequest(req, res);
|
||||
});
|
||||
const server = http.createServer(handleRequest);
|
||||
|
||||
// Graceful shutdown
|
||||
const shutdown = () => {
|
||||
|
||||
Reference in New Issue
Block a user