File size: 1,165 Bytes
b51f54a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const fetch = require('node-fetch');

async function addApiKey() {
  try {
    console.log('添加API Key...');
    const response = await fetch('http://localhost:3010/v1/api-keys', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        apiKey: 'test-key',
        cookieValues: ['test-cookie'],
      }),
    });
    
    console.log('响应状态:', response.status);
    
    if (!response.ok) {
      throw new Error(`HTTP错误: ${response.status} ${response.statusText}`);
    }
    
    const data = await response.json();
    console.log('响应数据:', data);
    
    // 测试获取API Keys
    console.log('\n测试获取API Keys...');
    const getResponse = await fetch('http://localhost:3010/v1/api-keys');
    
    console.log('响应状态:', getResponse.status);
    
    if (!getResponse.ok) {
      throw new Error(`HTTP错误: ${getResponse.status} ${getResponse.statusText}`);
    }
    
    const getData = await getResponse.json();
    console.log('获取到的数据:', getData);
  } catch (error) {
    console.error('操作失败:', error);
  }
}

addApiKey();