From 949ca790e12643c8d540405846fd99cd86f2bcdd Mon Sep 17 00:00:00 2001 From: buildingu Date: Sat, 6 Jul 2024 13:49:53 -0500 Subject: [PATCH] Update routes on FE Update backend origins --- .htaccess | 3 +++ index.js | 22 +++++++------------ package.json | 4 ++-- views/package.json | 2 +- views/src/API/index.js | 7 ++++-- views/src/Pages/Account.jsx | 3 ++- views/src/Pages/LoginPage.jsx | 3 ++- views/src/Pages/Signup.jsx | 5 +++-- views/src/Pages/SingleFeedbackPage.jsx | 5 +++-- views/src/Utility/AuthWrapper.jsx | 3 ++- views/src/data.js | 8 ------- views/src/features/Auth/authSlice.js | 3 ++- views/src/features/Feedbacks/feedbackSlice.js | 19 ++++++++-------- views/vite.config.js | 2 +- 14 files changed, 44 insertions(+), 45 deletions(-) create mode 100644 .htaccess delete mode 100644 views/src/data.js diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..26f0e99 --- /dev/null +++ b/.htaccess @@ -0,0 +1,3 @@ +RewriteEngine On +RewriteCond %{REQUEST_FILENAME} !-f +RewriteRule ^(.*)$ http://localhost:5001/$1 [P,L] \ No newline at end of file diff --git a/index.js b/index.js index ba7d803..a011268 100644 --- a/index.js +++ b/index.js @@ -5,26 +5,20 @@ const app = express(); const port = process.env.PORT || 5001 //////Express MiddleWares////////////// + +const prodOrigin = "https://buildingu.github.io/Building-u-feedback" + +//Use for local development +// const devOrigin = "http://localhost:5173" + const corsOptions = { - origin: "https://buildingu.github.io/Building-u-feedback/", + origin: prodOrigin, credentials: true, }; -//Uncomment the cors options below for local development -// const corsOptions = { -// origin: "http://localhost:5173", -// credentials: true, -// }; - app.use(cors(corsOptions)) app.use(express.urlencoded({ extended: false })) app.use(express.json()) -app.use(function(req, res, next) { - res.header('Access-Control-Allow-Origin', req.headers.origin); - res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); - next(); -}); - app.use(cookieParser()); @@ -37,7 +31,7 @@ app.use('/api/feedback', feedbackRouter); app.use('/api/password', passwordRouter); app.get('/',(req, res)=>{ -res.send(`

HELLO WORLD

`); + res.redirect('https://buildingu.github.io/Building-u-feedback/'); }) diff --git a/package.json b/package.json index 9e0c4f3..c589068 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "building-u-feedback-api", - "version": "v0.3.0-alpha", - "description": "Contains packages for the server", + "version": "v0.4.0-alpha", + "description": "This is for the server api that serves the app", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", diff --git a/views/package.json b/views/package.json index 336ccaf..312000a 100644 --- a/views/package.json +++ b/views/package.json @@ -1,6 +1,6 @@ { "name": "building-u-feedback", - "version": "v0.1.0-alpha", + "version": "v0.2.0-alpha", "homepage": "https://buildingu.github.io/Building-u-feedback", "type": "module", "scripts": { diff --git a/views/src/API/index.js b/views/src/API/index.js index 9ca965b..ccaa461 100644 --- a/views/src/API/index.js +++ b/views/src/API/index.js @@ -1,3 +1,6 @@ -export const feedBackAPI = "http://localhost:5001/api/feedback"; -export const userAPI = "http://localhost:5001/api/users"; +export const baseUrl = "https://building-u-feedback-api.building-u.com" + + +//Use the below for local testing +// export const baseUrl = "http://localhost:5001" diff --git a/views/src/Pages/Account.jsx b/views/src/Pages/Account.jsx index 975aae6..3502e62 100644 --- a/views/src/Pages/Account.jsx +++ b/views/src/Pages/Account.jsx @@ -10,6 +10,7 @@ import { } from "@mantine/core"; import { useForm } from "@mantine/form"; import { useDisclosure } from "@mantine/hooks"; +import {baseUrl} from "../API/index" const paperStyle = { padding: 40, @@ -63,7 +64,7 @@ function Account({ user }) { }; const response = await axios.patch( - "http://localhost:5001/api/users/updateaccount", + `${baseUrl}/api/users/updateaccount`, formData, { withCredentials: true, diff --git a/views/src/Pages/LoginPage.jsx b/views/src/Pages/LoginPage.jsx index 2bd6712..cd353b6 100644 --- a/views/src/Pages/LoginPage.jsx +++ b/views/src/Pages/LoginPage.jsx @@ -14,6 +14,7 @@ import { Center, Group, } from "@mantine/core"; +import { baseUrl } from "../API/index"; const homepageStyles = { display: "flex", @@ -56,7 +57,7 @@ function LoginPage() { try { const response = await axios.post( - "http://localhost:5001/api/users/login", + `${baseUrl}/api/users/login`, userData, { withCredentials: true, diff --git a/views/src/Pages/Signup.jsx b/views/src/Pages/Signup.jsx index 7ef5cc6..974b579 100644 --- a/views/src/Pages/Signup.jsx +++ b/views/src/Pages/Signup.jsx @@ -14,6 +14,7 @@ import { Center, Group, } from "@mantine/core"; +import { baseUrl } from "../API/index"; const homepageStyles = { display: "flex", @@ -60,7 +61,7 @@ function Signup() { try { const response = await axios.post( - "http://localhost:5001/api/users/register", + `${baseUrl}/api/users/register`, userData ); @@ -80,7 +81,7 @@ function Signup() { console.error("Error submitting the form data:", error); } } else { - // Handle the case when the form is not valid + // Handle the case when the form is not valid (TBD) return; } }; diff --git a/views/src/Pages/SingleFeedbackPage.jsx b/views/src/Pages/SingleFeedbackPage.jsx index 86814ee..6f899d3 100644 --- a/views/src/Pages/SingleFeedbackPage.jsx +++ b/views/src/Pages/SingleFeedbackPage.jsx @@ -6,6 +6,7 @@ import axios from "axios"; import TextEditor from "../components/TextEditor"; import formatCreatedAt from "../Utility/DateFormatter"; import { addFeedback } from "../features/Feedbacks/feedbackSlice"; +import { baseUrl } from "../API/index"; const feedbackContainer = { zIndex: "20", @@ -43,7 +44,7 @@ function SingleFeedbackPage(props) { try { // Make the API call using axios const response = await axios.get( - `http://localhost:5001/api/feedback/getMentorFeedback/${id}`, + `${baseUrl}/api/feedback/getMentorFeedback/${id}`, { withCredentials: true, } @@ -74,7 +75,7 @@ function SingleFeedbackPage(props) { const fetchData = async () => { try { const response = await axios.get( - `http://localhost:5001/api/feedback/getfeedbackid/${id}`, + `${baseUrl}/api/feedback/getfeedbackid/${id}`, { withCredentials: true, } diff --git a/views/src/Utility/AuthWrapper.jsx b/views/src/Utility/AuthWrapper.jsx index 5122d1d..e660d9f 100644 --- a/views/src/Utility/AuthWrapper.jsx +++ b/views/src/Utility/AuthWrapper.jsx @@ -2,6 +2,7 @@ import React, { useState, useEffect } from "react"; import axios from "axios"; import { useNavigate } from "react-router-dom"; import { useLocation } from "react-router-dom"; +import { baseUrl } from "../API/index"; const AuthWrapper = ({ children: ChildComponent }) => { const [user, setUser] = useState(false); @@ -12,7 +13,7 @@ const AuthWrapper = ({ children: ChildComponent }) => { const fetchUser = async () => { try { const response = await axios.get( - "http://localhost:5001/api/users/authorized", + `${baseUrl}/api/users/authorized`, { withCredentials: true, } diff --git a/views/src/data.js b/views/src/data.js deleted file mode 100644 index 76416be..0000000 --- a/views/src/data.js +++ /dev/null @@ -1,8 +0,0 @@ -const data = { - userId: 1, - username: "Test", - topicOfLearningSession: "TEST TOPIC", - codeLink: "www.test.com", -}; - -export default data; diff --git a/views/src/features/Auth/authSlice.js b/views/src/features/Auth/authSlice.js index fd6eea9..eb557f0 100644 --- a/views/src/features/Auth/authSlice.js +++ b/views/src/features/Auth/authSlice.js @@ -1,6 +1,7 @@ // authSlice.js import { createSlice, createAsyncThunk } from '@reduxjs/toolkit'; import axios from 'axios'; +import {baseUrl} from "../../API/index" const initialState = { @@ -15,7 +16,7 @@ export const logoutUser = createAsyncThunk('auth/logout', async (_, thunkAPI) => try { await axios.get( - 'http://localhost:5001/api/users/logout', + `${baseUrl}/api/users/logout'`, { withCredentials: true } diff --git a/views/src/features/Feedbacks/feedbackSlice.js b/views/src/features/Feedbacks/feedbackSlice.js index aff32db..e317adb 100644 --- a/views/src/features/Feedbacks/feedbackSlice.js +++ b/views/src/features/Feedbacks/feedbackSlice.js @@ -1,5 +1,6 @@ import { createSlice, createAsyncThunk } from "@reduxjs/toolkit"; import axios from "axios"; +import {baseUrl} from "../../API/index" const initialState = { feedbackRequests: [], @@ -40,44 +41,44 @@ const createAsyncThunkWithJwt = (type, url, method = "get") => const createFeedbackRequest = createAsyncThunkWithJwt( "feedback/create", - "http://localhost:5001/api/feedback/submitfeedback", - "post" + `${baseUrl}/api/feedback/submitfeedback", + "post` ); const addFeedback = createAsyncThunkWithJwt( "feedback/add", - "http://localhost:5001/api/feedback/addFeedBack/", + `${baseUrl}/api/feedback/addFeedBack/`, "post" ); const assignFeedbackRequest = createAsyncThunkWithJwt( "feedback/assign", - "http://localhost:5001/api/feedback/assignFeedBackToMentor/", + `${baseUrl}/api/feedback/assignFeedBackToMentor/`, "post" ); const getAssignedFeedbackRequests = createAsyncThunkWithJwt( "feedback/getAssign", - "http://localhost:5001/api/feedback/getAssignedFeedBacks" + `${baseUrl}/api/feedback/getAssignedFeedBacks` ); const fetchFeedbackRequests = createAsyncThunkWithJwt( "feedback/fetchAll", - "http://localhost:5001/api/feedback/getfeedbackrequestForms" + `${baseUrl}/api/feedback/getfeedbackrequestForms` ); const fetchInternFeedbackRequests = createAsyncThunkWithJwt( "feedback/fetchAll", - "http://localhost:5001/api/feedback/getUserFeedBackRequestForms" + `${baseUrl}/api/feedback/getUserFeedBackRequestForms` ); const getSelectedFeedbackRequest = createAsyncThunk( "feedback/getSelectedRequest", - "http://localhost:5001/api/feedback/getfeedbackid/" + `${baseUrl}/api/feedback/getfeedbackid/` ); const markComplete = createAsyncThunkWithJwt( "feedback/markComplete", - "http://localhost:5001/api/feedback/markFeedBackRequestComplete/", + `${baseUrl}/api/feedback/markFeedBackRequestComplete/`, "get" ); diff --git a/views/vite.config.js b/views/vite.config.js index 19d9285..6e8bc79 100644 --- a/views/vite.config.js +++ b/views/vite.config.js @@ -4,7 +4,7 @@ import react from '@vitejs/plugin-react'; // https://vitejs.dev/config/ export default defineConfig({ plugins: [react()], - base: '/Building-u-feedback/', // Add this line + base: '/Building-u-feedback/', ////Uncomment for local development only // server: {