Skip to content

Commit

Permalink
Merge pull request #32 from buildingu/chore-deploy-backend
Browse files Browse the repository at this point in the history
Update routes on FE
  • Loading branch information
gbudjeakp authored Jul 6, 2024
2 parents 9443b4f + 949ca79 commit dc67132
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 45 deletions.
3 changes: 3 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ http://localhost:5001/$1 [P,L]
22 changes: 8 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());


Expand All @@ -37,7 +31,7 @@ app.use('/api/feedback', feedbackRouter);
app.use('/api/password', passwordRouter);

app.get('/',(req, res)=>{
res.send(`<h1>HELLO WORLD</h1>`);
res.redirect('https://buildingu.github.io/Building-u-feedback/');
})


Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion views/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
7 changes: 5 additions & 2 deletions views/src/API/index.js
Original file line number Diff line number Diff line change
@@ -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"
3 changes: 2 additions & 1 deletion views/src/Pages/Account.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion views/src/Pages/LoginPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
Center,
Group,
} from "@mantine/core";
import { baseUrl } from "../API/index";

const homepageStyles = {
display: "flex",
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions views/src/Pages/Signup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
Center,
Group,
} from "@mantine/core";
import { baseUrl } from "../API/index";

const homepageStyles = {
display: "flex",
Expand Down Expand Up @@ -60,7 +61,7 @@ function Signup() {

try {
const response = await axios.post(
"http://localhost:5001/api/users/register",
`${baseUrl}/api/users/register`,
userData
);

Expand All @@ -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;
}
};
Expand Down
5 changes: 3 additions & 2 deletions views/src/Pages/SingleFeedbackPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
}
Expand Down
3 changes: 2 additions & 1 deletion views/src/Utility/AuthWrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
}
Expand Down
8 changes: 0 additions & 8 deletions views/src/data.js

This file was deleted.

3 changes: 2 additions & 1 deletion views/src/features/Auth/authSlice.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// authSlice.js
import { createSlice, createAsyncThunk } from '@reduxjs/toolkit';
import axios from 'axios';
import {baseUrl} from "../../API/index"


const initialState = {
Expand All @@ -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
}
Expand Down
19 changes: 10 additions & 9 deletions views/src/features/Feedbacks/feedbackSlice.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createSlice, createAsyncThunk } from "@reduxjs/toolkit";
import axios from "axios";
import {baseUrl} from "../../API/index"

const initialState = {
feedbackRequests: [],
Expand Down Expand Up @@ -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"
);

Expand Down
2 changes: 1 addition & 1 deletion views/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit dc67132

Please sign in to comment.