Skip to content

Commit 3c0a7fd

Browse files
author
james_tsai
committed
refactor: set endpoint url and accesstoken as instance variables
1 parent ef893c2 commit 3c0a7fd

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

nodejs/src/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import axios, { AxiosInstance, AxiosRequestConfig, AxiosError } from 'axios'
22
import { User, Note, Team, CreateNoteOptions, NotePermissionRole, CommentPermissionType } from './type'
33

44
export class API {
5-
public axios: AxiosInstance
6-
constructor(accessToken: string) {
5+
private axios: AxiosInstance
6+
7+
constructor(public hackmdAPIEndpointURL: string, readonly accessToken: string) {
78
this.axios = axios.create({
8-
baseURL: "http://localhost:3000/v1",
9+
baseURL: this.hackmdAPIEndpointURL,
910
headers:{
1011
"Content-Type": "application/json",
1112
}
@@ -14,11 +15,12 @@ export class API {
1415
this.axios.interceptors.request.use(
1516
(config: AxiosRequestConfig) =>{
1617
if (accessToken) {
17-
config.headers!.Authorization = `Bearer ${accessToken}`;
18+
config.headers!.Authorization = `Bearer ${this.accessToken}`;
1819
}
1920
return config
2021
},
2122
(err: AxiosError) => {
23+
console.log('request error')
2224
return Promise.reject(err)
2325
}
2426
)
@@ -50,6 +52,7 @@ export class API {
5052

5153
createNote = async (options: CreateNoteOptions) => {
5254
const { data } = await this.axios.post<Note>("notes", options)
55+
console.log(data)
5356
return data
5457
}
5558

@@ -82,7 +85,7 @@ export class API {
8285
}
8386

8487
updateTeamNoteContent =async (teamPath: string, noteId: string, content?: string) => {
85-
const { data } = await this.axios.patch<string>(`notes/${noteId}`, { content })
88+
const { data } = await this.axios.patch<string>(`teams/${teamPath}/notes/${noteId}`, { content })
8689
return data
8790
}
8891

@@ -96,6 +99,3 @@ export class API {
9699
}
97100
}
98101

99-
100-
101-

0 commit comments

Comments
 (0)