77 lines
2.0 KiB
JavaScript
77 lines
2.0 KiB
JavaScript
#!/usr/bin/env node
|
|
const http = require('http');
|
|
const { URL } = require('url');
|
|
|
|
async function testRegistration() {
|
|
const registerData = {
|
|
email: `debug.${Date.now()}@bakery.com`,
|
|
password: 'TestPassword123!',
|
|
full_name: 'Debug Test User',
|
|
role: 'admin'
|
|
};
|
|
|
|
const bodyString = JSON.stringify(registerData);
|
|
console.log('Request body:', bodyString);
|
|
console.log('Content-Length:', Buffer.byteLength(bodyString, 'utf8'));
|
|
|
|
const url = new URL('/api/v1/auth/register', 'http://localhost:8000');
|
|
|
|
const options = {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'Accept': 'application/json',
|
|
'User-Agent': 'Frontend-Debug/1.0',
|
|
'Content-Length': Buffer.byteLength(bodyString, 'utf8')
|
|
},
|
|
};
|
|
|
|
return new Promise((resolve, reject) => {
|
|
console.log('Making request to:', url.href);
|
|
console.log('Headers:', options.headers);
|
|
|
|
const req = http.request(url, options, (res) => {
|
|
console.log('Response status:', res.statusCode);
|
|
console.log('Response headers:', res.headers);
|
|
|
|
let data = '';
|
|
res.on('data', (chunk) => {
|
|
data += chunk;
|
|
});
|
|
|
|
res.on('end', () => {
|
|
console.log('Response body:', data);
|
|
|
|
try {
|
|
const parsedData = data ? JSON.parse(data) : {};
|
|
|
|
if (res.statusCode >= 200 && res.statusCode < 300) {
|
|
resolve(parsedData);
|
|
} else {
|
|
reject(new Error(`HTTP ${res.statusCode}: ${JSON.stringify(parsedData)}`));
|
|
}
|
|
} catch (e) {
|
|
console.log('JSON parse error:', e.message);
|
|
reject(new Error(`HTTP ${res.statusCode}: ${data}`));
|
|
}
|
|
});
|
|
});
|
|
|
|
req.on('error', (error) => {
|
|
console.log('Request error:', error);
|
|
reject(error);
|
|
});
|
|
|
|
console.log('Writing body:', bodyString);
|
|
req.write(bodyString);
|
|
req.end();
|
|
});
|
|
}
|
|
|
|
testRegistration()
|
|
.then(result => {
|
|
console.log('✅ Success:', result);
|
|
})
|
|
.catch(error => {
|
|
console.log('❌ Error:', error.message);
|
|
}); |