Skip to content

Commit 94086bc

Browse files
committed
feat: add api config and refactor api-instance
1 parent 62c9c42 commit 94086bc

2 files changed

Lines changed: 19 additions & 6 deletions

File tree

src/config/api.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export const COPILOT_CONFIG = {
2+
baseURL: "https://api.individual.githubcopilot.com",
3+
headers: {
4+
"copilot-integration-id": "vscode-chat",
5+
},
6+
} as const
7+
8+
export const GITHUB_CONFIG = {
9+
baseURL: "https://api.github.com",
10+
} as const
11+
12+
export const GITHUB_WEB_CONFIG = {
13+
baseURL: "https://github.com",
14+
} as const

src/services/api-instance.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import consola from "consola"
22
import { FetchError, ofetch } from "ofetch"
33

4+
import { COPILOT_CONFIG, GITHUB_CONFIG, GITHUB_WEB_CONFIG } from "~/config/api"
45
import { TOKENS } from "~/config/tokens"
56

67
export const copilot = ofetch.create({
7-
baseURL: "https://api.individual.githubcopilot.com",
8-
headers: {
9-
"copilot-integration-id": "vscode-chat",
10-
},
8+
baseURL: COPILOT_CONFIG.baseURL,
9+
headers: COPILOT_CONFIG.headers,
1110

1211
onRequest({ options }) {
1312
options.headers.set("authorization", `Bearer ${TOKENS.COPILOT_TOKEN}`)
@@ -33,7 +32,7 @@ export const copilot = ofetch.create({
3332
})
3433

3534
export const github = ofetch.create({
36-
baseURL: "https://api.github.com",
35+
baseURL: GITHUB_CONFIG.baseURL,
3736

3837
onRequest({ options }) {
3938
options.headers.set("authorization", `token ${TOKENS.GITHUB_TOKEN}`)
@@ -42,5 +41,5 @@ export const github = ofetch.create({
4241

4342
// Only used for device flow auth
4443
export const _github = ofetch.create({
45-
baseURL: "https://github.com",
44+
baseURL: GITHUB_WEB_CONFIG.baseURL,
4645
})

0 commit comments

Comments
 (0)