Skip to content

Commit

Permalink
fix: apiのURLをenvから設定できるようにした
Browse files Browse the repository at this point in the history
  • Loading branch information
watasuke102 committed Jan 16, 2024
1 parent 662b28e commit b40c01b
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions sample-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import {Env} from '@mytypes/env';

export const env: Env = {
API_URL: '',
GOOGLE_CLIENT_ID: '',
GOOGLE_CLIENT_SECRET: '',
SESSION_OPTION: {
Expand Down
1 change: 1 addition & 0 deletions src/types/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import {SessionOptions} from 'iron-session';

export type Env = {
API_URL: string;
GOOGLE_CLIENT_ID: string;
GOOGLE_CLIENT_SECRET: string;
SESSION_OPTION: SessionOptions;
Expand Down
5 changes: 3 additions & 2 deletions src/utils/api/category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@ import {AllCategoryDataType, CategoryDataType} from '@mytypes/Category';
import {NewCategory} from 'src/app/api/category/route';
import {PutCategory} from 'src/app/api/category/[id]/route';
import {tag_key} from './tag';

Check failure on line 13 in src/utils/api/category.ts

View workflow job for this annotation

GitHub Actions / check (20)

'tag_key' is defined but never used

Check failure on line 13 in src/utils/api/category.ts

View workflow job for this annotation

GitHub Actions / check (20)

'tag_key' is defined but never used

Check failure on line 13 in src/utils/api/category.ts

View workflow job for this annotation

GitHub Actions / check (20)

'tag_key' is defined but never used

Check failure on line 13 in src/utils/api/category.ts

View workflow job for this annotation

GitHub Actions / check (20)

'tag_key' is defined but never used
import {env} from 'env';

export const category_key = '/api/category';

export const mutate_category = (): Promise<void> => mutate(category_key);
export const useAllCategoryData = useApiData<AllCategoryDataType[]>(category_key);

export function fetch_category_data(id: number | string): Promise<CategoryDataType> {
return fetcher(`http://localhost:3009${category_key}/${id}`);
return fetcher(`${env.API_URL}${category_key}/${id}`);
}
// 特定のタグが付けられているすべてのカテゴリ
export function fetch_category_with_spec_tag_data(tag_id: number | string): Promise<CategoryDataType> {
return fetcher(`http://localhost:3009${tag_key}/${tag_id}/all_category`);
return fetcher(`${env.API_URL}{tag_key}/${tag_id}/all_category`);
}

export async function new_category(data: NewCategory): AxiosPromise {
Expand Down
3 changes: 2 additions & 1 deletion src/utils/api/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import axios, {AxiosPromise} from 'axios';
import {fetcher, useApiData} from './common';
import {AllHistory, History} from '@mytypes/ExamHistory';
import {NewHistory} from 'src/app/api/history/route';
import {env} from 'env';

export const history_key = '/api/history';

export const mutate_history = (): Promise<void> => mutate(history_key);
export const useAllHistory = useApiData<AllHistory[]>(history_key);

export function fetch_history(id: string): Promise<History> {
return fetcher(`http://localhost:3009${history_key}/${id}`);
return fetcher(`${env.API_URL}${history_key}/${id}`);
}

export async function new_history(data: NewHistory): AxiosPromise {
Expand Down
3 changes: 2 additions & 1 deletion src/utils/api/tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import {fetcher, useApiData} from './common';
import TagData from '@mytypes/TagData';
import {PutTag} from 'src/app/api/tag/[id]/route';
import {PostTag} from 'src/app/api/tag/route';
import {env} from 'env';

export const tag_key = '/api/tag';

export const mutate_tag = (): Promise<void> => mutate(tag_key);
export const useTagData = useApiData<TagData[]>(tag_key);
export function fetch_tag(): Promise<TagData[]> {
return fetcher(`http://localhost:3009${tag_key}`);
return fetcher(env.API_URL + tag_key);
}

export async function new_tag(data: PostTag): Promise<AxiosPromise> {
Expand Down

0 comments on commit b40c01b

Please sign in to comment.