diff --git a/sample-env.ts b/sample-env.ts index 8d1eec17..568bcd72 100644 --- a/sample-env.ts +++ b/sample-env.ts @@ -7,6 +7,7 @@ import {Env} from '@mytypes/env'; export const env: Env = { + API_URL: '', GOOGLE_CLIENT_ID: '', GOOGLE_CLIENT_SECRET: '', SESSION_OPTION: { diff --git a/src/types/env.d.ts b/src/types/env.d.ts index 43c1ef28..cc2c91c7 100644 --- a/src/types/env.d.ts +++ b/src/types/env.d.ts @@ -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; diff --git a/src/utils/api/category.ts b/src/utils/api/category.ts index 69c795be..8770fc8a 100644 --- a/src/utils/api/category.ts +++ b/src/utils/api/category.ts @@ -11,6 +11,7 @@ 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'; +import {env} from 'env'; export const category_key = '/api/category'; @@ -18,11 +19,11 @@ export const mutate_category = (): Promise => mutate(category_key); export const useAllCategoryData = useApiData(category_key); export function fetch_category_data(id: number | string): Promise { - 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 { - 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 { diff --git a/src/utils/api/history.ts b/src/utils/api/history.ts index c9745657..7bb8c9d0 100644 --- a/src/utils/api/history.ts +++ b/src/utils/api/history.ts @@ -9,6 +9,7 @@ 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'; @@ -16,7 +17,7 @@ export const mutate_history = (): Promise => mutate(history_key); export const useAllHistory = useApiData(history_key); export function fetch_history(id: string): Promise { - return fetcher(`http://localhost:3009${history_key}/${id}`); + return fetcher(`${env.API_URL}${history_key}/${id}`); } export async function new_history(data: NewHistory): AxiosPromise { diff --git a/src/utils/api/tag.ts b/src/utils/api/tag.ts index 072445e8..438b3f3c 100644 --- a/src/utils/api/tag.ts +++ b/src/utils/api/tag.ts @@ -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 => mutate(tag_key); export const useTagData = useApiData(tag_key); export function fetch_tag(): Promise { - return fetcher(`http://localhost:3009${tag_key}`); + return fetcher(env.API_URL + tag_key); } export async function new_tag(data: PostTag): Promise {