Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

186
Views
inserting header axios async thunk

I'm trying to set apikey in the header of req-- it gives me Cors error when done locally, though when done on postman it goes through

export const fetchCreativeAd = createAsyncThunk(
  'creativeAd/fetchCreativeAd',
  async (payload, thunkAPI) => {
    try {
      const urlParam = process.env.NEXT_PUBLIC_AWS_ENDPOINT;
      const response = await axios.get(
        `${urlParam}/creative_ad?product_name=${payload.productName}&product_description=${payload.productDescription}&platform=${payload.platform}&audience=${payload.audience}&ad_tone=${payload.adTone}`,
        {
          headers: {
            'x-api-key': `${process.env.NEXT_PUBLIC_AWS_API_KEY}`,
          },
        }
      );
      res.data.headers['x-api-key'];
      console.log(process.env.NEXT_PUBLIC_AWS_API_KEY);
      return response;
    } catch (error) {
      return thunkAPI.rejectWithValue({ error: error.message });
    }
  }
);

Cors error:

Access to XMLHttpRequest at '"urlParam"creative_ad?product_name=asdf&product_description=asdf&platform=asdf&audience=asdf&ad_tone=asdf' 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.

how do I insert the header portion in axios?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!