Skip to content

Commit

Permalink
Merge pull request #99 from JangGusWjd/fix/api-env
Browse files Browse the repository at this point in the history
[FE-FIX, REF] api url env 분리, 챗봇 api 연결 리팩토링
  • Loading branch information
JangGusWjd authored Aug 29, 2024
2 parents 69a9870 + b0a1269 commit d82ce05
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*

.env
2 changes: 1 addition & 1 deletion src/api/fetchData.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from "axios";

const API_BASE_URL = "http://3.35.123.253/api";
const API_BASE_URL = process.env.REACT_APP_SERVER_URL;

export const fetchData = async (endpoint: string) => {
const storedAuth = localStorage.getItem("auth");
Expand Down
2 changes: 1 addition & 1 deletion src/api/postData.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from "axios";

const API_BASE_URL = "http://3.35.123.253/api";
const API_BASE_URL = process.env.REACT_APP_SERVER_URL;

export const postData = async (endpoint: string, data: any) => {
try {
Expand Down
2 changes: 1 addition & 1 deletion src/api/postStudentCard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from "axios";

const API_BASE_URL = "http://3.37.196.198:8000";
const API_BASE_URL = process.env.REACT_APP_AI_URL;

export const postStudentCard = async (file: File) => {
const formData = new FormData();
Expand Down
15 changes: 4 additions & 11 deletions src/components/mentoring/MenteeChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Gif from "../../assets/img/gif.gif";
import "../../styles/mentoring/MenteeChat.scss";
import { useState } from "react";
import axios from "axios";
import { postTextData } from "../../api/postData";

interface ChatMessage {
sender: "me" | "gpt";
Expand Down Expand Up @@ -36,17 +37,9 @@ const MenteeChat = () => {
setMessage("");

try {
const storedAuth = localStorage.getItem("auth");
const auth = storedAuth ? JSON.parse(storedAuth) : null;
const accessToken = auth ? auth.access_token : null;
const response = await axios.post(
"http://3.35.123.253/api/mentorings/chat_with_gpt/",
{ message: userMessage },
{
headers: {
Authorization: `Bearer ${accessToken}`,
},
}
const response = await postTextData(
"/mentorings/chat_with_gpt/",
userMessage
);

if (response.status === 200) {
Expand Down

0 comments on commit d82ce05

Please sign in to comment.