Skip to content

Commit

Permalink
Merge pull request #28 from scienmanas/mvp
Browse files Browse the repository at this point in the history
Fix CORS
  • Loading branch information
scienmanas authored Dec 14, 2024
2 parents 86fb54b + 672c34d commit 283d72d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
24 changes: 17 additions & 7 deletions Website/Backend/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,28 @@ const app: Express = express();
const PORT: string = process.env.PORT || "5000";

// CORS configuration: Manually handle origins and preflight requests
const allowedOrigins = ["https://certimailer.xyz"];
const allowedOrigins = [
"https://certimailer.xyz",
"https://www.certimailer.xyz",
];
const allowedOriginsHitPoint = [
"https://certimailer.xyz",
"https://www.certimailer.xyz",
"https://cron-job.org",
"https://www.cron-job.org",
"http://localhost:3000",
];
const allowedMethods = ["GET", "POST", "PUT", "DELETE"];
const allowedHeaders = ["Content-Type", "Authorization"];

app.use((req: Request, res: Response, next) => {
const origin = req.headers.origin as string | undefined;

if (req.url === "/") {
if (origin && allowedOriginsHitPoint.includes(origin))
return res.status(200).json({ message: "200 OK Hello guys :)" }).end();
}

if (origin && allowedOrigins.includes(origin)) {
// Allow the origin if it's in the allowedOrigins list
res.setHeader("Access-Control-Allow-Origin", origin);
Expand All @@ -39,7 +54,7 @@ app.use((req: Request, res: Response, next) => {
if (req.method === "OPTIONS") {
return res.status(200).end();
}
} else {
} else {
// If origin doesn't match, send a 403 error
return res.status(403).json({ message: "Access denied: Not allowed" });
}
Expand All @@ -58,11 +73,6 @@ app.use("/api/send-email", sendEmailsRoute);
app.use("/user", userRoute);
app.use("/api/utils", utilsRoute);

// Landing endpoint
app.get("/", (req: Request, res: Response) => {
res.status(200).json({ message: "200 OK Hello guys :)" });
});

// Start server
app.listen(PORT, () => {
console.log(`Server active at port: ${PORT}`);
Expand Down
2 changes: 0 additions & 2 deletions Website/Frontend/app/ui/universal/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ export function Navbar(): JSX.Element {
hasMounted.current = true;
setMounted(true);
if (theme === "system") {
console.log(theme);
setWebsiteTheme("light");
setTheme("light");
} else if (theme === "dark" || theme === "light") {
console.log(theme);
setWebsiteTheme(theme); // Set the website theme based on next-themes
}
}
Expand Down

0 comments on commit 283d72d

Please sign in to comment.