Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/lib/api.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
const axios = require('axios');
const https = require('node:https');
const http = require('node:http');
const pkg = require('../../package.json');

// Identifies requests as coming from the CLI (e.g. "vnext-workflow-cli/1.0.0")
const USER_AGENT = `vnext-workflow-cli/${pkg.version}`;

// Create axios instance with custom agents for both HTTP and HTTPS
const apiClient = axios.create({
httpAgent: new http.Agent({ keepAlive: true }),
httpsAgent: new https.Agent({
httpsAgent: new https.Agent({
rejectUnauthorized: false // Allow self-signed certificates
})
}),
headers: { 'User-Agent': USER_AGENT }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Setting headers at the instance level may override axios’s per-method default headers.

Passing a flat headers object into axios.create can overwrite axios’s per-method defaults (e.g. Content-Type on POST/PUT). To avoid dropping these, either set apiClient.defaults.headers.common['User-Agent'] = USER_AGENT after creation, or use headers: { common: { 'User-Agent': USER_AGENT } } so existing defaults are preserved.

});

/**
Expand All @@ -18,8 +23,7 @@ const apiClient = axios.create({
async function testApiConnection(baseUrl) {
try {
const response = await apiClient.get(`${baseUrl}/health`, {
timeout: 5000,
headers: { 'User-Agent': USER_AGENT }
timeout: 5000
});
return response.status === 200;
} catch (error) {
Expand Down
Loading