Skip to content

Commit 362987f

Browse files
author
Lasim
committed
refactor(satellite): enhance headers for Cloudflare compatibility
1 parent 7aa72ca commit 362987f

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"github.copilot.chat.commitMessageGeneration.instructions": [
33
{
4-
"text": "Generate commit messages following the Conventional Commits specification with MANDATORY scope for monorepo. Use this structure:\n\n<type>(<scope>): <description>\n\nRules:\n1. **SCOPE IS MANDATORY** - Must be one of: frontend, backend, satellite, shared, all, ci, deps\n2. **Type must be one of**: feat, fix, docs, style, refactor, perf, test, build, ci, chore\n3. **Description**: Imperative mood, no period at end, max 72 characters\n4. **Examples**:\n - feat(frontend): add dark mode toggle\n - fix(backend): resolve database connection issue\n - feat(satellite): implement MCP server process management\n - chore(deps): update dependencies\n - docs(all): update README installation guide\n - refactor(shared): extract common utilities\n\nAlways include the scope to ensure proper changelog filtering per service. Use 'all' scope only for changes affecting multiple services or project-wide changes."
4+
"text": "Generate commit messages following the Conventional Commits specification with MANDATORY scope for monorepo. Use this structure:\n\n<type>(<scope>): <description>\n\nRules:\n1. **SCOPE IS MANDATORY** - Determine scope from file path:\n - Files in services/frontend/ → scope: frontend\n - Files in services/backend/ → scope: backend\n - Files in services/satellite/ → scope: satellite\n - Files in services/shared/ → scope: shared\n - Files in .github/ → scope: ci\n - package.json, package-lock.json → scope: deps\n - Multiple services or root files → scope: all\n\n2. **Type must be one of**: feat, fix, docs, style, refactor, perf, test, build, ci, chore\n\n3. **Description**: Imperative mood, no period at end, max 72 characters\n\n4. **Examples**:\n - services/frontend/src/App.vue → feat(frontend): add dark mode toggle\n - services/backend/src/routes/auth.ts → fix(backend): resolve database connection issue\n - services/satellite/src/services/backend-client.ts → refactor(satellite): enhance headers for Cloudflare compatibility\n - services/shared/utils/logger.ts → refactor(shared): extract common utilities\n - package.json → chore(deps): update dependencies\n - README.md → docs(all): update installation guide\n\nAlways include the scope to ensure proper changelog filtering per service."
55
}
66
],
77
"github.copilot.chat.codeGeneration.useInstructionFiles": true

services/satellite/src/services/backend-client.ts

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { platform, arch, totalmem } from 'os';
33
import { readFile, writeFile, access } from 'fs/promises';
44
import { join } from 'path';
55
import { SatelliteEvent } from '../events/registry';
6+
import { getVersionString } from '../config/version';
67

78
export interface BackendConnectionStatus {
89
backend_url: string;
@@ -122,12 +123,25 @@ export class BackendClient {
122123
}
123124

124125
/**
125-
* Get authentication headers
126+
* Get base browser-like headers for Cloudflare compatibility
126127
*/
127-
private getAuthHeaders(): Record<string, string> {
128-
const headers: Record<string, string> = {
129-
'Content-Type': 'application/json'
128+
private getBaseHeaders(): Record<string, string> {
129+
return {
130+
'Content-Type': 'application/json',
131+
'User-Agent': `DeployStack-Satellite/${getVersionString()} (Node.js)`,
132+
'Accept': 'application/json, text/plain, */*',
133+
'Accept-Language': 'en-US,en;q=0.9',
134+
'Accept-Encoding': 'gzip, deflate, br',
135+
'Cache-Control': 'no-cache',
136+
'Connection': 'keep-alive'
130137
};
138+
}
139+
140+
/**
141+
* Get authentication headers with API key
142+
*/
143+
private getAuthHeaders(): Record<string, string> {
144+
const headers = this.getBaseHeaders();
131145

132146
if (this.apiKey) {
133147
headers['Authorization'] = `Bearer ${this.apiKey}`;
@@ -151,9 +165,7 @@ export class BackendClient {
151165
// Try to connect to backend health endpoint
152166
const response = await fetch(`${this.backendUrl}/api/health`, {
153167
method: 'GET',
154-
headers: {
155-
'Content-Type': 'application/json'
156-
},
168+
headers: this.getBaseHeaders(),
157169
// 5 second timeout
158170
signal: AbortSignal.timeout(5000)
159171
});
@@ -235,12 +247,12 @@ export class BackendClient {
235247
satellite_name: registrationData.name
236248
}, 'Registering satellite with backend');
237249

250+
const headers = this.getBaseHeaders();
251+
headers['Authorization'] = `Bearer ${registrationToken}`;
252+
238253
const response = await fetch(`${this.backendUrl}/api/satellites/register`, {
239254
method: 'POST',
240-
headers: {
241-
'Content-Type': 'application/json',
242-
'Authorization': `Bearer ${registrationToken}`
243-
},
255+
headers: headers,
244256
body: JSON.stringify(registrationData),
245257
// 10 second timeout for registration
246258
signal: AbortSignal.timeout(10000)

0 commit comments

Comments
 (0)