11import * as vscode from 'vscode'
2- import axios from 'axios'
2+ import * as http from 'http'
3+ import * as https from 'https'
4+ import { URL } from 'url'
35import { getUIStorageField , setUIStorageField } from './lib'
46
57/*
@@ -56,13 +58,76 @@ async function getBackendBaseUrl(): Promise<string> {
5658 return `http://localhost:${ appPort } `
5759}
5860
61+ // Helper function to make HTTP requests using Node.js built-in modules
62+ async function makeHttpRequest (
63+ url : string ,
64+ method : 'GET' | 'POST' | 'DELETE' = 'GET' ,
65+ data ?: any ,
66+ ) : Promise < any > {
67+ return new Promise ( ( resolve , reject ) => {
68+ const parsedUrl = new URL ( url )
69+ const isHttps = parsedUrl . protocol === 'https:'
70+ const httpModule = isHttps ? https : http
71+
72+ const headers : { [ key : string ] : string | number } = {
73+ 'Content-Type' : 'application/json' ,
74+ }
75+
76+ if ( data && method === 'POST' ) {
77+ const postData = JSON . stringify ( data )
78+ headers [ 'Content-Length' ] = Buffer . byteLength ( postData )
79+ }
80+
81+ const options = {
82+ hostname : parsedUrl . hostname ,
83+ port : parsedUrl . port || ( isHttps ? 443 : 80 ) ,
84+ path : parsedUrl . pathname + parsedUrl . search ,
85+ method,
86+ headers,
87+ }
88+
89+ const req = httpModule . request ( options , ( res ) => {
90+ let responseData = ''
91+
92+ res . on ( 'data' , ( chunk ) => {
93+ responseData += chunk
94+ } )
95+
96+ res . on ( 'end' , ( ) => {
97+ try {
98+ const parsedData = responseData ? JSON . parse ( responseData ) : { }
99+ resolve ( {
100+ status : res . statusCode ,
101+ data : parsedData ,
102+ } )
103+ } catch ( error ) {
104+ resolve ( {
105+ status : res . statusCode ,
106+ data : responseData ,
107+ } )
108+ }
109+ } )
110+ } )
111+
112+ req . on ( 'error' , ( error ) => {
113+ reject ( error )
114+ } )
115+
116+ if ( data && method === 'POST' ) {
117+ req . write ( JSON . stringify ( data ) )
118+ }
119+
120+ req . end ( )
121+ } )
122+ }
123+
59124// Helper function to execute Redis CLI command on a database
60125async function executeCliCommand ( databaseId : string , command : string ) : Promise < CliCommandResponse | null > {
61126 try {
62127 const baseUrl = await getBackendBaseUrl ( )
63128
64129 // First create a CLI client for the database
65- const createResponse = await axios . post ( `${ baseUrl } /databases/${ databaseId } /cli` )
130+ const createResponse = await makeHttpRequest ( `${ baseUrl } /databases/${ databaseId } /cli` , 'POST' )
66131
67132 if ( createResponse . status !== 201 ) {
68133 console . error ( 'Failed to create CLI client' )
@@ -78,16 +143,17 @@ async function executeCliCommand(databaseId: string, command: string): Promise<C
78143
79144 try {
80145 // Execute the command
81- const commandResponse = await axios . post (
146+ const commandResponse = await makeHttpRequest (
82147 `${ baseUrl } /databases/${ databaseId } /cli/${ cliClientUuid } /send-command` ,
148+ 'POST' ,
83149 {
84150 command,
85151 outputFormat : 'RAW' ,
86152 } ,
87153 )
88154
89155 // Clean up: delete the CLI client
90- await axios . delete ( `${ baseUrl } /databases/${ databaseId } /cli/${ cliClientUuid } ` )
156+ await makeHttpRequest ( `${ baseUrl } /databases/${ databaseId } /cli/${ cliClientUuid } ` , 'DELETE' )
91157
92158 if ( commandResponse . status === 200 ) {
93159 return {
@@ -100,7 +166,7 @@ async function executeCliCommand(databaseId: string, command: string): Promise<C
100166 } catch ( error ) {
101167 // Clean up: delete the CLI client even if command execution failed
102168 try {
103- await axios . delete ( `${ baseUrl } /databases/${ databaseId } /cli/${ cliClientUuid } ` )
169+ await makeHttpRequest ( `${ baseUrl } /databases/${ databaseId } /cli/${ cliClientUuid } ` , 'DELETE' )
104170 } catch ( cleanupError ) {
105171 console . error ( 'Failed to cleanup CLI client:' , cleanupError )
106172 }
@@ -119,7 +185,7 @@ async function executeCliCommand(databaseId: string, command: string): Promise<C
119185export async function getAllDatabases ( ) : Promise < DatabaseInstance [ ] > {
120186 try {
121187 const baseUrl = await getBackendBaseUrl ( )
122- const response = await axios . get ( `${ baseUrl } /databases` )
188+ const response = await makeHttpRequest ( `${ baseUrl } /databases` )
123189
124190 if ( response . status === 200 && Array . isArray ( response . data ) ) {
125191 return response . data . map ( ( db : any ) => ( {
0 commit comments