R
R
Roqvie2020-08-03 23:50:25
JavaScript
Roqvie, 2020-08-03 23:50:25

How to change CORS?

There is an API and Lambda on AWS, I created a small script, uploaded it to the hosting. In him:

...
let response = fetch(url, {
    mode: 'no-cors',
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
    },
    body: JSON.stringify(body)
})
.then( data => {
    return data.json();
})
.then( data => {
    console.log(data);
});
...


in lambda:
...
return {
            'statusCode': 200,
            'headers': {
                "Access-Control-Allow-Headers": "Content-Type",
                "Access-Control-Allow-Origin": "*", 
                "Access-Control-Allow-Credentials" : True,
                'Access-Control-Allow-Methods': 'POST,GET'
            },
            'body': body
        }
...


But the script still doesn't like it. I myself do not understand much about this, I did what they advise on the Internet. But now I can't find anything, I don't know how to fix it.

Upon request, the following error appears in the console:
Uncaught (in promise) SyntaxError: Unexpected end of input
    at script.js:19


5f2880a68a85a881856981.jpeg

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Nikolaev, 2020-08-15
@kaleniybrat

And what comes in data ? Maybe it doesn't have a json method

O
OCTAGRAM, 2020-10-29
@OCTAGRAM

mode: 'no-cors',
clean up

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question