-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: large refactor to commonize axios client
- Loading branch information
1 parent
cafc5d4
commit 148b771
Showing
21 changed files
with
230 additions
and
431 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
{ | ||
"environment": "development" | ||
"environment": "development", | ||
|
||
"api": { | ||
"endpoint": "http://127.0.0.1:8000/v1/" | ||
} | ||
} |
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,7 @@ | ||
{ | ||
"environment": "production" | ||
"environment": "production", | ||
|
||
"api": { | ||
"endpoint": "/api/v1/" | ||
} | ||
} |
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,44 @@ | ||
/* | ||
* This file is part of prose-pod-dashboard | ||
* | ||
* Copyright 2024, Prose Foundation | ||
*/ | ||
|
||
/************************************************************************** | ||
* IMPORTS | ||
* ************************************************************************* */ | ||
|
||
// NPM | ||
import { default as axios, AxiosInstance } from "axios"; | ||
|
||
// PROJECT: COMMONS | ||
import CONFIG from "@/commons/config"; | ||
|
||
/************************************************************************** | ||
* STORE | ||
* ************************************************************************* */ | ||
|
||
class API { | ||
public readonly client: AxiosInstance; | ||
|
||
constructor() { | ||
// Initialize API HTTP client | ||
this.client = this.__createClient(); | ||
} | ||
|
||
private __createClient(): AxiosInstance { | ||
return axios.create({ | ||
baseURL: CONFIG.api.endpoint, | ||
|
||
headers: { | ||
"Content-Type": "application/json" | ||
} | ||
}); | ||
} | ||
} | ||
|
||
/************************************************************************** | ||
* EXPORTS | ||
* ************************************************************************* */ | ||
|
||
export default new API(); |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
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
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,47 @@ | ||
/* | ||
* This file is part of prose-pod-dashboard | ||
* | ||
* Copyright 2024, Prose Foundation | ||
*/ | ||
|
||
/************************************************************************** | ||
* IMPORTS | ||
* ************************************************************************* */ | ||
|
||
// PROJECT: API | ||
import Api from "@/api"; | ||
|
||
/************************************************************************** | ||
* INTERFACES | ||
* ************************************************************************* */ | ||
|
||
interface LoginResponse { | ||
token: string; | ||
} | ||
|
||
/************************************************************************** | ||
* API | ||
* ************************************************************************* */ | ||
|
||
class APILogin { | ||
async login(username: string, password: string): Promise<LoginResponse> { | ||
return ( | ||
await Api.client.post<LoginResponse>( | ||
"/login", | ||
{}, | ||
{ | ||
auth: { | ||
username, | ||
password | ||
} | ||
} | ||
) | ||
).data; | ||
} | ||
} | ||
|
||
/************************************************************************** | ||
* EXPORTS | ||
* ************************************************************************* */ | ||
|
||
export default new APILogin(); |
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
Oops, something went wrong.