Sorry for asking this question when it's a lot of answers to these questions out there already, but I have tried almost everything and it's still not working. I'm making an API call to an API hosted on replit. This has worked fine until yesterday, I don't know what I did yesterday that f*cked up my code. When making the API call, I get the CORS error: No 'Access-Control-Allow-Origin' header is present on the requested resource, but I have a header with 'Access-Control-Allow-Origin' in my response.
Really appreciate all your help!
API code:
app.use(bodyParser.urlencoded({ extended: true }))
app.use(bodyParser.json())
app.use(cors())
app.post('/invoicing', cors(), async (req, res) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('crossorigin', 'true')
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
try {
const product = await stripe.products.create({
name: 'Test'
})
const price = await stripe.prices.create({
product: product.id,
unit_amount: 10000,
currency: 'nok',
})
const customer = await stripe.customers.create({
name: 'Daniel Olsen',
email: 'olsen.daniel04@gmail.com',
description: 'Customer',
})
const invoiceItem = await stripe.invoiceItems.create({
customer: customer.id,
price: price.id,
})
const invoice = await stripe.invoices.create({
customer: customer.id,
auto_advance: true,
})
const invoiceFinalize = await stripe.invoices.finalizeInvoice(invoice.id)
console.log(invoiceFinalize)
console.log(customer)
res.json({
success: true,
message: 'Yeeet'
})
} catch (error) {
console.log(error)
res.json({
message: "Payment failed",
success: false
})
}
})