Skip to content

Commit

Permalink
Update cors policy (#57)
Browse files Browse the repository at this point in the history
* Update allowedOrigin

* Update allowedOrigin

* Update allowedOrigin

* Update allowedOrigin

* Update cors policy

* Update cors policy

* Update cors policy

* Remove node module and update https to http
  • Loading branch information
Kang-Quan authored Oct 20, 2023
1 parent 02894ed commit a7fc9be
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
6 changes: 0 additions & 6 deletions front-end/package-lock.json

This file was deleted.

8 changes: 4 additions & 4 deletions front-end/peer-prep/src/components/UserPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const UserPage = () => {
useEffect(() => {
axios({
method: "get",
url: `https://api.peerprepgroup51sem1y2023.xyz/users/${authUid}`,
url: `http://api.peerprepgroup51sem1y2023.xyz/users/${authUid}`,
})
.then((response) => {
const data = response.data.data;
Expand Down Expand Up @@ -96,7 +96,7 @@ const UserPage = () => {
// First time creation for new user if user does not exist.
const postUserData = () => {
axios
.post(`https://api.peerprepgroup51sem1y2023.xyz/users/`, {
.post(`http://api.peerprepgroup51sem1y2023.xyz/users/`, {
username: currentUsername,
email: currentEmail,
firstName: currentFirstName,
Expand All @@ -119,7 +119,7 @@ const UserPage = () => {
// Updates user data after editing.
const putUserData = () =>
axios
.put(`https://api.peerprepgroup51sem1y2023.xyz/users/${authUid}`, {
.put(`http://api.peerprepgroup51sem1y2023.xyz/users/${authUid}`, {
username: currentUsername,
email: currentEmail,
firstName: currentFirstName,
Expand All @@ -145,7 +145,7 @@ const UserPage = () => {
// Deletes user data from postgres database.
const deleteUserData = () => {
axios
.delete(`https://api.peerprepgroup51sem1y2023.xyz/users/${authUid}`)
.delete(`http://api.peerprepgroup51sem1y2023.xyz/users/${authUid}`)
.catch(() => {});
};

Expand Down
4 changes: 2 additions & 2 deletions front-end/peer-prep/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import SignInPage from "./components/Auth/SignInPage";
import Navbar from "./components/Navbar";
import GoodbyePage from "./components/Auth/GoodbyePage";
import VerificationPage from "./components/Auth/VerificationPage";
import DeletePage from "./components/DeletePage"
import DeletePage from "./components/DeletePage";

import axios from "axios";

Expand Down Expand Up @@ -73,7 +73,7 @@ const RedirectUserRoute = () => {
}
axios({
method: "get",
url: `https://api.peerprepgroup51sem1y2023.xyz/users/${uid}`,
url: `http://api.peerprepgroup51sem1y2023.xyz/users/${uid}`,
}).catch((error) => {
console.log(error);
dispatch(UserSlice.setIsFirstTimeLogin(true));
Expand Down
13 changes: 11 additions & 2 deletions services/profile-service/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import bodyParser from "body-parser";
import cors from "cors";
import express, { Express, NextFunction, Request, Response } from "express";
import "reflect-metadata";
import userRoutes from "./router/user-routes";

var cors = require("cors");

const app = express();

// Configure CORS to allow our front-end domain to access the APIs
Expand All @@ -14,7 +15,7 @@ const corsOptions = {
"https://app.peerprepgroup51sem1y2023.xyz",
"http://localhost:3000",
];
if (!origin || allowedOrigins.includes(origin)) {
if (!origin) {
callback(null, true);
} else {
callback(new Error("Not allowed by CORS"));
Expand All @@ -23,6 +24,14 @@ const corsOptions = {
};

app.use(cors(corsOptions));

// app.use(
// cors({
// origin: "*", // Allow requests from any origin
// })
// );

//app.use(cors());
app.use(bodyParser.json());

app.use("/users", userRoutes);
Expand Down

0 comments on commit a7fc9be

Please sign in to comment.