1

I was trying to make a html file with form to send notification for my react-native app users.

I am using expo push notification, when I try to execute this code:

    const sendNotification = async (token, titre, news) => {
        const message = {
            to: token,
            sound: 'default',
            title: titre,
            body: news,
            data: { data: 'goes here' },
        };
        var request = new Request('https://exp.host/--/api/v2/push/send');
        const url = 'https://exp.host/--/api/v2/push/send';
        await fetch(request, {
            method: 'POST',
            headers: {
                Accept: 'application/json',
                'Accept-encoding': 'gzip, deflate',
                'Content-Type': 'application/json',
            },
            body: JSON.stringify(message),
        });
    };

I got CORS error.

I make some research about this and I find a lot of things about node js web app but nothing about pure js in an html file..

Any solution?

samuel
  • 477
  • 7
  • 21
  • 1
    Are you running this application using any server or just with HTML and browser? – Gautham Nov 17 '20 at 08:57
  • just HTML and browser.. – samuel Nov 17 '20 at 08:58
  • 1
    You can not fix this CORS error only with front-end javascript. You need to allow CORS on the server side. – York Chen Nov 17 '20 at 09:00
  • 1
    Ya just HTML and browser will not resolve CORS you need run it in some server and stated by York Chen you need to allow CORS on the server side. Try as stated in the [link](https://stackoverflow.com/questions/38497334/how-to-run-html-file-on-localhost) It servers your folder structure from the location in which you have started the server. – Gautham Nov 17 '20 at 09:10

0 Answers0