新增資料庫、用戶註冊、登入的功能

This commit is contained in:
2025-08-05 10:56:22 +08:00
parent 94e3763402
commit a288a966ba
41 changed files with 4362 additions and 289 deletions

80
scripts/simple-test.js Normal file
View File

@@ -0,0 +1,80 @@
const http = require('http');
// 簡單的 HTTP 請求函數
function makeSimpleRequest(url, method = 'GET', body = null) {
return new Promise((resolve, reject) => {
const urlObj = new URL(url);
const options = {
hostname: urlObj.hostname,
port: urlObj.port,
path: urlObj.pathname,
method: method,
headers: {
'Content-Type': 'application/json'
}
};
const req = http.request(options, (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
try {
const jsonData = JSON.parse(data);
resolve({
status: res.statusCode,
data: jsonData
});
} catch (error) {
resolve({
status: res.statusCode,
data: data
});
}
});
});
req.on('error', (error) => {
reject(error);
});
if (body) {
req.write(JSON.stringify(body));
}
req.end();
});
}
async function testSimple() {
console.log('🧪 簡單 API 測試...\n');
try {
// 測試健康檢查
console.log('1⃣ 測試健康檢查...');
const health = await makeSimpleRequest('http://localhost:3000/api');
console.log(` 狀態碼: ${health.status}`);
console.log(` 回應: ${JSON.stringify(health.data, null, 2)}`);
console.log('');
// 測試註冊 API
console.log('2⃣ 測試註冊 API...');
const register = await makeSimpleRequest('http://localhost:3000/api/auth/register', 'POST', {
name: '測試用戶',
email: 'test@example.com',
password: 'Test@2024',
department: '測試部門'
});
console.log(` 狀態碼: ${register.status}`);
console.log(` 回應: ${JSON.stringify(register.data, null, 2)}`);
} catch (error) {
console.error('❌ 測試失敗:', error.message);
}
}
testSimple();