首页 > 解决方案 > 纯 html 文件和 vanilla js 中的 CORS 错误

问题描述

我试图制作一个带有表单的 html 文件,以便为我的 react-native 应用程序用户发送通知。

当我尝试执行此代码时,我正在使用 expo 推送通知:

    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),
        });
    };

我收到 CORS 错误。

我对此进行了一些研究,我发现了很多关于 node js web 应用程序的东西,但没有关于 html 文件中的纯 js 的东西。

有什么解决办法吗?

标签: javascripthtmlreact-native

解决方案


推荐阅读