Skip to content

Commit

Permalink
Add CORS policy (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
Acerizm authored Oct 19, 2023
1 parent 056f8e6 commit e919fb9
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion services/profile-service/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,23 @@ import userRoutes from "./router/user-routes";

const app = express();

app.use(cors());
// Configure CORS to allow our front-end domain to access the APIs
// Before the end of this project, allows CORS for localhost too
const corsOptions = {
origin: (origin, callback) => {
const allowedOrigins = [
"https://app.peerprepgroup51sem1y2023.xyz",
"http://localhost"
];
if (!origin || allowedOrigins.includes(origin)) {
callback(null, true);
} else {
callback(new Error("Not allowed by CORS"));
}
},
};

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

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

0 comments on commit e919fb9

Please sign in to comment.