specify custom api url for client
This commit is contained in:
parent
dd07580943
commit
0397efba8a
|
|
@ -1,8 +1,9 @@
|
||||||
import { Cookies } from "react-cookie";
|
import { Cookies } from "react-cookie";
|
||||||
|
import { api } from "../main";
|
||||||
|
|
||||||
const likePost = async (id: string) => {
|
const likePost = async (id: string) => {
|
||||||
const token = new Cookies().get('token');
|
const token = new Cookies().get('token');
|
||||||
const response = await fetch(`/api/posts/like/${id}`, {
|
const response = await fetch(`${api}/posts/like/${id}`, {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
mode: 'cors',
|
mode: 'cors',
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -19,7 +20,7 @@ const likePost = async (id: string) => {
|
||||||
|
|
||||||
const unlikePost = async (id: string) => {
|
const unlikePost = async (id: string) => {
|
||||||
const token = new Cookies().get('token');
|
const token = new Cookies().get('token');
|
||||||
const response = await fetch(`/api/posts/unlike/${id}`, {
|
const response = await fetch(`${api}/posts/unlike/${id}`, {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
mode: 'cors',
|
mode: 'cors',
|
||||||
headers: {
|
headers: {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
import { Cookies } from 'react-cookie';
|
import { Cookies } from 'react-cookie';
|
||||||
|
import { api } from '../main';
|
||||||
|
|
||||||
const getMessages = async () => {
|
const getMessages = async () => {
|
||||||
const token = new Cookies().get('token');
|
const token = new Cookies().get('token');
|
||||||
const response = await fetch('/api/posts', {
|
const response = await fetch(api + '/posts', {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
|
|
@ -17,7 +18,7 @@ const getMessages = async () => {
|
||||||
|
|
||||||
const newMessage = async (data: FormData) => {
|
const newMessage = async (data: FormData) => {
|
||||||
const token = new Cookies().get('token');
|
const token = new Cookies().get('token');
|
||||||
const response = await fetch('/api/posts/new', {
|
const response = await fetch(api + '/posts/new', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: data,
|
body: data,
|
||||||
mode: 'cors',
|
mode: 'cors',
|
||||||
|
|
@ -30,7 +31,7 @@ const newMessage = async (data: FormData) => {
|
||||||
|
|
||||||
const deleteMessage = async (id: string) => {
|
const deleteMessage = async (id: string) => {
|
||||||
const token = new Cookies().get('token');
|
const token = new Cookies().get('token');
|
||||||
const response = await fetch(`/api/posts/delete/${id}`, {
|
const response = await fetch(`${api}/posts/delete/${id}`, {
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
|
|
@ -41,7 +42,7 @@ const deleteMessage = async (id: string) => {
|
||||||
|
|
||||||
const editMessage = async (id: string, data: FormData) => {
|
const editMessage = async (id: string, data: FormData) => {
|
||||||
const token = new Cookies().get('token');
|
const token = new Cookies().get('token');
|
||||||
const response = await fetch(`/api/posts/edit/${id}`, {
|
const response = await fetch(`${api}/posts/edit/${id}`, {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
body: data,
|
body: data,
|
||||||
mode: 'cors',
|
mode: 'cors',
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
import { Cookies } from 'react-cookie';
|
import { Cookies } from 'react-cookie';
|
||||||
|
import { api } from '../main';
|
||||||
|
|
||||||
const getMeInfo = async () => {
|
const getMeInfo = async () => {
|
||||||
const token = new Cookies().get('token');
|
const token = new Cookies().get('token');
|
||||||
|
|
||||||
const response = await fetch('/api/me', {
|
const response = await fetch(api + '/me', {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
mode: 'cors',
|
mode: 'cors',
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -21,7 +22,7 @@ const getMeInfo = async () => {
|
||||||
const login = async ({ email, password }: { email: string; password: string }) => {
|
const login = async ({ email, password }: { email: string; password: string }) => {
|
||||||
const token = new Cookies().get('token');
|
const token = new Cookies().get('token');
|
||||||
|
|
||||||
const response = await fetch('/api/auth/login', {
|
const response = await fetch(api + '/auth/login', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({ email, password }),
|
body: JSON.stringify({ email, password }),
|
||||||
mode: 'cors',
|
mode: 'cors',
|
||||||
|
|
@ -51,7 +52,7 @@ const signup = async (formData: FormData) => {
|
||||||
throw 'Passwords do not match';
|
throw 'Passwords do not match';
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await fetch('/api/auth/signup', {
|
const response = await fetch(api + '/auth/signup', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify(form),
|
body: JSON.stringify(form),
|
||||||
mode: 'cors',
|
mode: 'cors',
|
||||||
|
|
@ -69,7 +70,7 @@ const signup = async (formData: FormData) => {
|
||||||
export const giveUserRights = async (userId: string, role: string) => {
|
export const giveUserRights = async (userId: string, role: string) => {
|
||||||
const token = new Cookies().get('token');
|
const token = new Cookies().get('token');
|
||||||
|
|
||||||
const response = await fetch(`/api/users/${userId}/roles`, {
|
const response = await fetch(`${api}/users/${userId}/roles`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
mode: 'cors',
|
mode: 'cors',
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -117,7 +118,7 @@ export const changeUserInfo = async (userId: string, formData: FormData) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await fetch(`/api/users/${userId}`, {
|
const response = await fetch(`${api}/users/${userId}`, {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
mode: 'cors',
|
mode: 'cors',
|
||||||
headers: {
|
headers: {
|
||||||
|
|
|
||||||
|
|
@ -3,3 +3,10 @@ import App from './App';
|
||||||
import './index.css';
|
import './index.css';
|
||||||
|
|
||||||
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(<App />);
|
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(<App />);
|
||||||
|
|
||||||
|
let api = '/api';
|
||||||
|
if (import.meta.env.VITE_API_URL) {
|
||||||
|
api = import.meta.env.VITE_API_URL;
|
||||||
|
}
|
||||||
|
|
||||||
|
export { api };
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue