-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove axios from the dependency list
- Loading branch information
1 parent
bfe7ea3
commit 72641f4
Showing
8 changed files
with
164 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import http from 'http'; | ||
import https from 'https'; | ||
|
||
type Response<Data> = { | ||
status?: number | ||
statusText?: string | ||
headers: http.IncomingHttpHeaders | ||
body: string | ||
data: Data | ||
} | ||
|
||
export const jsonFetch = <Data>(url: string): Promise<Response<Data>> => { | ||
return new Promise((resolve, reject) => { | ||
// Parse the URL | ||
const parsedUrl = new URL(url); | ||
|
||
// Determine the protocol module (http or https) | ||
const protocol = parsedUrl.protocol === 'https:' ? https : http; | ||
|
||
// Prepare the request options | ||
const options = { | ||
hostname: parsedUrl.hostname, | ||
port: parsedUrl.port, | ||
path: parsedUrl.pathname + parsedUrl.search, | ||
method: 'GET', | ||
}; | ||
|
||
// Send the request | ||
const req = protocol.request(options, (res) => { | ||
let body = ''; | ||
|
||
// Accumulate the response data | ||
res.on('data', (chunk) => { | ||
body += chunk; | ||
}); | ||
|
||
// Resolve the promise when the response ends | ||
res.on('end', () => { | ||
try { | ||
const data = JSON.parse(body); | ||
resolve({ | ||
status: res.statusCode, | ||
statusText: res.statusMessage, | ||
headers: res.headers, | ||
body, | ||
data, | ||
}); | ||
} catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
}); | ||
|
||
// Handle request errors | ||
req.on('error', (error) => { | ||
reject(error); | ||
}); | ||
|
||
// End the request | ||
req.end(); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
FIGMA_APP_CLIENT_SECRET= | ||
FIGMA_APP_CLIENT_ID= | ||
FIGMA_APP_REDIRECT_URI=http://localhost:3000/api/auth | ||
FIGMA_APP_REDIRECT_URI=http://127.0.0.1:3000/api/auth |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters