Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

스테이징 서버 추가 #144

Merged
merged 2 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/auth/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NEXT_PUBLIC_API_BASE_URL=프로덕션_주소
NEXT_PUBLIC_TEST_API_BASE_URL=스테이징_주소
21 changes: 11 additions & 10 deletions apps/auth/src/api/auth.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ServerResponse } from '@/src/types/server';
import { type ServiceCode } from '@utils/service';

import { API_BASE_URL, END_POINTS } from '../constants/api';
import { END_POINTS, createURL } from '../constants/api';

export interface PostLoginData {
id: string;
Expand All @@ -18,8 +18,7 @@ export interface PostTwoFactorLoginData {
* 멤버 로그인
*/
export const postLogin = async (data: PostLoginData) => {
const url = API_BASE_URL + END_POINTS.LOGIN;
const response = await fetch(url, {
const response = await fetch(createURL(data.code, END_POINTS.LOGIN), {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand All @@ -44,14 +43,16 @@ export const postLogin = async (data: PostLoginData) => {
* TOTP 인증
*/
export const postTwoFactorLogin = async (data: PostTwoFactorLoginData) => {
const url = API_BASE_URL + END_POINTS.TWO_FACTOR_LOGIN;
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
const response = await fetch(
createURL(data.code, END_POINTS.TWO_FACTOR_LOGIN),
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
},
body: JSON.stringify(data),
});
);

if (!response.ok) {
throw new Error('Network response was not ok');
Expand Down
10 changes: 9 additions & 1 deletion apps/auth/src/constants/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
export const API_BASE_URL = 'https://api.clab.page/api';
import { type ServiceCode } from '@utils/service';

export const API_BASE_URL = process.env.NEXT_PUBLIC_API_BASE_URL; // 프로덕션 환경
export const TEST_API_BASE_URL = process.env.NEXT_PUBLIC_TEST_API_BASE_URL; // 스테이징 환경

export function createURL(code: ServiceCode, url: string) {
const baseURL = code === 'dev' ? TEST_API_BASE_URL : API_BASE_URL;
return baseURL + url;
}

export const END_POINTS = {
LOGIN: '/v1/login',
Expand Down