Skip to content

Commit

Permalink
cors issue solving
Browse files Browse the repository at this point in the history
  • Loading branch information
RamakrushnaBiswal committed Oct 12, 2024
1 parent 253c0f3 commit ce98cef
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const express = require("express");
const cors = require("cors");
const mongoose = require("mongoose");
const dotenv = require("dotenv");
const logger = require("./config/logger"); // Import your logger
const logger = require("./config/logger");
const errorMiddleware = require("./middlewares/errrorMiddleware");

dotenv.config();
Expand All @@ -19,8 +19,11 @@ app.use(
// CORS configuration
const corsOptions = {
origin: ["http://localhost:5173", "https://play-cafe.vercel.app"],
optionsSuccessStatus: 200,
};

app.use(cors(corsOptions));

app.use(express.json());

// MongoDB connection
Expand All @@ -38,11 +41,13 @@ mongoose
});

// Enable CORS preflight for the create reservation route only
app.options("/api/reservation/create", cors(corsOptions));
// app.options("/api/reservation/create", cors(corsOptions));

// API routes
app.use("/api", require("./routes/index"));

app.options("*", cors(corsOptions));

// Health Check Endpoint
app.get("/health", (req, res) => {
res.status(200).json({ status: "OK" });
Expand Down

0 comments on commit ce98cef

Please sign in to comment.