-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathBase.ts
More file actions
54 lines (44 loc) · 1.27 KB
/
Base.ts
File metadata and controls
54 lines (44 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import 'core-js/full/array/from-async';
import { HTTPClient } from 'koajax';
import { githubClient } from 'mobx-github';
import { DataObject } from 'mobx-restful';
import { isEmpty } from 'web-utility';
import {
API_Host,
GithubToken,
isServer,
ProxyBaseURL,
} from './configuration';
export const ownClient = new HTTPClient({
baseURI: `${API_Host}/api/`,
responseType: 'json',
});
if (!isServer()) githubClient.baseURI = `${API_Host}/api/GitHub/`;
githubClient.use(({ request }, next) => {
if (GithubToken)
request.headers = {
authorization: `Bearer ${GithubToken}`,
...request.headers,
};
return next();
});
export { githubClient };
export const githubRawClient = new HTTPClient({
baseURI: `${ProxyBaseURL}/raw.githubusercontent.com/`,
responseType: 'arraybuffer',
});
export interface GithubSearchData<T> {
total_count: number;
incomplete_results: boolean;
items: T[];
}
export const makeGithubSearchCondition = (queryMap: DataObject) =>
Object.entries(queryMap)
.filter(([, value]) => !isEmpty(value))
.map(([key, value]) => `${key}:${value}`)
.join(' ');
// Strapi client for China NGO Database
export const strapiClient = new HTTPClient({
baseURI: 'https://china-ngo-db.onrender.com/api/',
responseType: 'json',
});