R
Railway10mo ago
RTXPower

CORS Issue

I'm getting a CORS issue even tho I have put my production url as the value of FRONTEND_URL and CORS_ORIGIN. I suppose the program is not detecting these ENV variables within Railway? Or did I make a mistake in my code? Locally with .env file it works tho
// Node.js example using Express
const express = require("express");
if (process.env.NODE_ENV !== 'production') {
require('dotenv').config();
}

const cors = require("cors");
const app = express();
const stripe = require("stripe")(process.env.STRIPE_SECRET_KEY);
app.use(express.json());
app.use(cors({ origin: process.env.CORS_ORIGIN }));

app.post("/create-checkout-session", async (req, res) => {
const { products } = req.body;

console.log("products",products);

try {
const session = await stripe.checkout.sessions.create({
payment_method_types: ["card"],
line_items: products,
mode: "payment",
success_url: `${process.env.FRONTEND_URL}/checkout/success`,
cancel_url: `${process.env.FRONTEND_URL}/cart`,
payment_intent_data: {
statement_descriptor: process.env.STATEMENT_DESCRIPTOR,
},
});

console.log(session.id);

res.json({ id: session.id });
} catch (error) {
res.status(500).send(error.toString());
}
});

app.listen(3000, () => console.log("Running on port 3000"));
// Node.js example using Express
const express = require("express");
if (process.env.NODE_ENV !== 'production') {
require('dotenv').config();
}

const cors = require("cors");
const app = express();
const stripe = require("stripe")(process.env.STRIPE_SECRET_KEY);
app.use(express.json());
app.use(cors({ origin: process.env.CORS_ORIGIN }));

app.post("/create-checkout-session", async (req, res) => {
const { products } = req.body;

console.log("products",products);

try {
const session = await stripe.checkout.sessions.create({
payment_method_types: ["card"],
line_items: products,
mode: "payment",
success_url: `${process.env.FRONTEND_URL}/checkout/success`,
cancel_url: `${process.env.FRONTEND_URL}/cart`,
payment_intent_data: {
statement_descriptor: process.env.STATEMENT_DESCRIPTOR,
},
});

console.log(session.id);

res.json({ id: session.id });
} catch (error) {
res.status(500).send(error.toString());
}
});

app.listen(3000, () => console.log("Running on port 3000"));
No description
No description
No description
No description
2 Replies
Percy
Percy10mo ago
Project ID: 3337bbd9-871e-41a3-a35e-ace982a5dc04
RTXPower
RTXPowerOP10mo ago
3337bbd9-871e-41a3-a35e-ace982a5dc04 This issue is resolved
Want results from more Discord servers?
Add your server