async function signUp(username, password) {
    try {
        const response = await fetch('http://localhost:3000/signup', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({
                username,
                password
            })
        });

        const data = await response.json();
        
        if (!response.ok) {
            throw new Error(data.error || '注册失败');
        }

        console.log('注册成功:', data.message);
        return data;
    } catch (error) {
        console.error('注册错误:', error.message);
        throw error;
    }
}

// 使用示例
signUp('newuser', 'password123')
    .then(() => console.log('注册流程完成'))
    .catch(() => console.log('注册流程失败'));