# Running Netlify functions locally

**URL:** <https://answers.netlify.com/t/running-netlify-functions-locally/27103>\
**Category:** Support\
**Tags:** lambda-functions\
**Created:** [November 25, 2020, 7:37pm UTC](https://answers.netlify.com/t/running-netlify-functions-locally/27103 "2020-11-25T19:37:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yepstein1](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/yepstein1/32/12728_2.png) [@yepstein1](https://answers.netlify.com/u/yepstein1)\
**Post date:** [November 25, 2020, 7:37pm UTC](https://answers.netlify.com/t/running-netlify-functions-locally/27103/1 "2020-11-25T19:37:10Z")

</div>

Hi, when I try to run my netlify fuctions locally using Netlify- Dev I get a cross-origin error. What is the simplest way to fix this? This is error message

 ![image](https://global.discourse-cdn.com/netlify/original/3X/9/b/9b5991b3d0726b45b6a0135d7de12dc717ed294f.png)

This is from network tab-  
 ![image](https://global.discourse-cdn.com/netlify/original/3X/8/a/8a9b99283b8fb1fb888e5bc27699532eb94406f1.png)

This is the netlify function  
exports.handler = async (event, context) =\> {

```
const stripe = require('stripe')(process.env.REACT_APP_STRIPE_SK);

var info = JSON.parse(event.body);

const session = await stripe.checkout.sessions.create({
    payment_method_types: ['card'],
    line_items: [
        {
            price_data: {
                currency: 'usd',
                product_data: {
                    name: `Pies: ${info.pies} Fries: ${info.fries} `,

                },
                unit_amount: info.total * 100,
            },
            quantity: 1,
        },
    ],
    mode: 'payment',
    success_url: `https://pies-and-fries.netlify.app`,
    cancel_url: 'https://pies-and-fries.netlify.app?info=canceled',
});
console.log("hi from func")
const headers = {
    'Access-Control-Allow-Origin': '*',
    'Access-Control-Allow-Headers': 'Content-Type',
    'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE'
};

return {
    statusCode: 200,
    headers,
    body: JSON.stringify({
        sessionId: session.id,
        orderInfo: info
    }),

}

```

}  
This is the code that calls the function

```
     const stripe = await stripePromise;

    const response = await fetch("https://pies-and-fries.netlify.app/.netlify/functions/acceptPayment", {

        method: 'POST', headers: {

            'Content-Type': 'application/json',

            'Access-Control-Allow-Origin': '*',

            'Access-Control-Allow-Headers': 'Content-Type',

            'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE'

        },

        body: JSON.stringify(abbreviatedState)

    });

    const session = await response.json();

    // When the customer clicks on the button, redirect them to Checkout.

    const result = await stripe.redirectToCheckout({

        sessionId: session.sessionId

    });

    result.then(() => {

        console.log(JSON.stringify(result))

    })

    if (result.error) {

        console.log(result.error.message)

        // If `redirectToCheckout` fails due to a browser or network

        // error, display the localized error message to your customer

        // using `result.error.message`.

    }

    //this.props.methodToPassToChild('confirmed');

}

```

Any help would be appreciated- it would be great to be able to make changes without pushing them to production. My site is [https://pies-and-fries.netlify.app/](https://pies-and-fries.netlify.app/)

---

<div class="post-metadata">

**Author:** ![AaronP](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/aaronp/32/14904_2.png) [@AaronP](https://answers.netlify.com/u/AaronP)\
**Post date:** [November 25, 2020, 9:22pm UTC](https://answers.netlify.com/t/running-netlify-functions-locally/27103/2 "2020-11-25T21:22:01Z")

</div>

When calling fetch have you tried calling `/.netlify/functions/acceptPayment` without the absolute url? I think netlify dev includes a built in proxy to the functions run on port 8888

---

<div class="post-metadata">

**Author:** ![AaronP](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/aaronp/32/14904_2.png) [@AaronP](https://answers.netlify.com/u/AaronP)\
**Post date:** [November 27, 2020, 11:19pm UTC](https://answers.netlify.com/t/running-netlify-functions-locally/27103/3 "2020-11-27T23:19:32Z")

</div>

glad to help 🙂 I faced these same issues
