Skip to content
Open
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
6 changes: 4 additions & 2 deletions client/.env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
VITE_API_URL=
# # VITE_API_URL=http://localhost:3000/api
# VITE_API_URL=https://snip-shell-2.onrender.com/api
# VITE_API_URL=https://snip-shell-2.onrender.com

VITE_ENV="development"
# VITE_ENV="development" or VITE_ENV="deployment"
39 changes: 21 additions & 18 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions client/src/hooks/AddContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import React, { useContext, createContext } from "react";
import axios from "axios";
import RedAlert from "../components/Alert/RedAlert";
import BlueAlert from "../components/Alert/BlueAlert";
const API_URL = import.meta.env.VITE_API_URL;
import { API_URL } from "../utils/constants";

interface ContentData {
title: string;
type: string;
Expand All @@ -28,7 +29,7 @@ export const AddProvider = ({ children }: { children: React.ReactNode }) => {

try {
await axios.post(
`${API_URL}/content`,
`${API_URL}/api/content`,
data, // send data directly or { title, link, type, description }, // directly create object here
{
headers: {
Expand Down
12 changes: 3 additions & 9 deletions client/src/hooks/AuthContext.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useState, createContext, useContext } from "react";
import axios from "axios";

// const API_URL = import.meta.env.VITE_API_URL ;
import { API_URL, environment } from "../utils/constants";

export interface UserData {
_id: string;
Expand Down Expand Up @@ -35,16 +34,11 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
/* we can even write (email: string, password: string) here and use it in the function below */
}
try {
const res = await axios.post("https://snip-shell-2.onrender.com/api/signin", {
const res = await axios.post(`${API_URL}/api/signin`, {
email: data.email,
password: data.password,
});

// similar one
// const Signin = async (email: string, password: string) => {
// try {
// const res = await axios.post("https://snip-shell-2.onrender.com/api/signin", { email, password });

// Save token
localStorage.setItem("token", res.data.token);

Expand All @@ -62,7 +56,7 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => {

const Signup = async (data: AuthData) => {
try {
const res = await axios.post("https://snip-shell-2.onrender.com/api/signup", {
const res = await axios.post(`${API_URL}/api/signup`, {
username: data.username,
email: data.email,
password: data.password,
Expand Down
8 changes: 4 additions & 4 deletions client/src/pages/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import Card from "../components/Card/Card";
import axios from "axios";
import ShareModalContent from "../components/modal/ShareModalContent";
import { motion } from "motion/react";
import { API_URL } from "../utils/constants";

const API_URL = import.meta.env.VITE_API_URL;
// import RedAlert from "../components/Alert/RedAlert";
interface CardData {
_id: string;
Expand Down Expand Up @@ -35,7 +35,7 @@ const Dashboard = () => {
const token = localStorage.getItem("token");

try {
await axios.delete(`${API_URL}/content`, {
await axios.delete(`${API_URL}/api/content`, {
headers: { Authorization: `${token}` },
data: { contentId: id },
});
Expand All @@ -55,7 +55,7 @@ const Dashboard = () => {
}

try {
const response = await axios.get(`${API_URL}/content`, {
const response = await axios.get(`${API_URL}/api/content`, {
headers: { Authorization: `${token}` },
});

Expand All @@ -72,7 +72,7 @@ const Dashboard = () => {
}, []);

const handleChange = (
e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement>
e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement>,
) => {
setFormData({ ...formData, [e.target.name]: e.target.value });
};
Expand Down
3 changes: 3 additions & 0 deletions client/src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ export const snipShellIntro: SnipShellIntro[] = [
"Tweets, threads, YouTube videos, tutorials, blog posts, tools — save anything."
}
];

export const environment = import.meta.env.VITE_ENV;
export const API_URL = environment === "development" ? "http://localhost:3000" : import.meta.env.VITE_API_URL ;