vercel / micro

Asynchronous HTTP microservices

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cess to XMLHttpRequest at 'http://localhost:8080/api/payment/orders' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. xhr.js:210

kumarnilesh890 opened this issue · comments

const express = require("express");
const cors = require("cors");
const dotenv = require("dotenv");
const paymentRoutes = require("./Routes/payment");
const app = express();

dotenv.config();

app.use(express.json());
app.use(cors());
app.options('', cors());
app.use(
cors({
origin: true,
optionsSuccessStatus: 200,
credentials: true,
})
);
app.options(
'
',
cors({
origin: true,
optionsSuccessStatus: 200,
credentials: true,
})
);
app.use("/api/payment/", paymentRoutes);

// const corsOrigin ={
// origin:'http://localhost:3000', //or whatever port your frontend is using
// optionSuccessStatus:200,
// methods: "GET, POST"
// }
// app.use(cors(corsOrigin));

// app.use(cors());
// app.get("/", (req,res)=>{
// res.send("server working");
// });

const port = process.env.PORT || 5001;
app.listen(port, () => console.log(Listening on port ${port}...));