Skip to content

Commit

Permalink
feat: support configuring proxy endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ifyour committed Nov 13, 2023
1 parent 87917e2 commit f067347
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/query.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RequestParams, RawResponseParams, ResponseParams } from './types';
import { RequestParams, RawResponseParams, ResponseParams, Config } from './types';

Check failure on line 1 in src/query.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 18.x and ubuntu-latest

Replace `·RequestParams,·RawResponseParams,·ResponseParams,·Config·` with `⏎··RequestParams,⏎··RawResponseParams,⏎··ResponseParams,⏎··Config,⏎`
import { API_URL, REQUEST_ALTERNATIVES } from './const';

function buildRequestParams(sourceLang = 'auto', targetLang = 'en') {
Expand Down Expand Up @@ -49,7 +49,7 @@ function buildRequestBody(data: RequestParams) {
return requestString;
}

async function query(params: RequestParams): Promise<ResponseParams> {
async function query(params: RequestParams, config?: Config): Promise<ResponseParams> {

Check failure on line 52 in src/query.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 18.x and ubuntu-latest

Replace `params:·RequestParams,·config?:·Config` with `⏎··params:·RequestParams,⏎··config?:·Config⏎`
if (!params?.text) {
return {
code: 404,
Expand All @@ -58,7 +58,7 @@ async function query(params: RequestParams): Promise<ResponseParams> {
};
}

const response = await fetch(API_URL, {
const response = await fetch(config?.proxyEndpoint ?? API_URL, {
headers: {
'Content-Type': 'application/json; charset=utf-8',
},
Expand Down
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ export type ResponseParams = {
target_lang?: string;
alternatives?: string[];
};

export type Config = {
proxyEndpoint?: string;
}

Check failure on line 34 in src/types.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 18.x and ubuntu-latest

Insert `;`

0 comments on commit f067347

Please sign in to comment.