liurenchaxin/test-hyperdrive.js

93 lines
3.0 KiB
JavaScript

// Simple test script for Hyperdrive configuration
// This script helps verify the wrangler.toml configuration
console.log('🚀 Hyperdrive NeonDB Test Configuration');
console.log('=====================================');
// Check if wrangler.toml exists and has correct configuration
const fs = require('fs');
const path = require('path');
try {
const wranglerPath = path.join(__dirname, 'wrangler.toml');
if (fs.existsSync(wranglerPath)) {
console.log('✅ wrangler.toml found');
const content = fs.readFileSync(wranglerPath, 'utf8');
// Check for Hyperdrive configuration
if (content.includes('hyperdrive')) {
console.log('✅ Hyperdrive configuration found');
} else {
console.log('❌ Hyperdrive configuration missing');
}
// Check for binding
if (content.includes('binding = "HYPERDRIVE"')) {
console.log('✅ HYPERDRIVE binding configured');
} else {
console.log('❌ HYPERDRIVE binding missing');
}
// Check for Hyperdrive ID
if (content.includes('ef43924d89064cddabfaccf06aadfab6')) {
console.log('✅ Hyperdrive ID configured');
} else {
console.log('❌ Hyperdrive ID missing');
}
// Check for nodejs_compat
if (content.includes('nodejs_compat')) {
console.log('✅ nodejs_compat flag enabled');
} else {
console.log('❌ nodejs_compat flag missing');
}
} else {
console.log('❌ wrangler.toml not found');
}
// Check if src/index.ts exists
const indexPath = path.join(__dirname, 'src', 'index.ts');
if (fs.existsSync(indexPath)) {
console.log('✅ src/index.ts found');
} else {
console.log('❌ src/index.ts missing');
}
// Check if package.json exists
const packagePath = path.join(__dirname, 'package.json');
if (fs.existsSync(packagePath)) {
console.log('✅ package.json found');
const packageContent = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
// Check for required dependencies
if (packageContent.dependencies && packageContent.dependencies.pg) {
console.log('✅ pg dependency configured');
} else {
console.log('❌ pg dependency missing');
}
if (packageContent.devDependencies && packageContent.devDependencies['@cloudflare/workers-types']) {
console.log('✅ Cloudflare Workers types configured');
} else {
console.log('❌ Cloudflare Workers types missing');
}
}
console.log('\n📋 Next Steps:');
console.log('1. Run: wrangler dev --local (for local testing)');
console.log('2. Run: wrangler dev (for remote testing with Hyperdrive)');
console.log('3. Test endpoints:');
console.log(' - http://localhost:8787/test-connection');
console.log(' - http://localhost:8787/test-query');
console.log('\n🔧 Hyperdrive Configuration:');
console.log(' - Hyperdrive ID: ef43924d89064cddabfaccf06aadfab6');
console.log(' - Binding: HYPERDRIVE');
console.log(' - Database: NeonDB (PostgreSQL)');
} catch (error) {
console.error('❌ Error checking configuration:', error.message);
}