简体   繁体   English

Runkit-请求的资源上不存在“ Access-Control-Allow-Origin”标头

[英]Runkit - No 'Access-Control-Allow-Origin' header is present on the requested resource

var cors = require("cors");

cors({ origin: '*' });
cors({ allowHeaders: 'X-PINGOTHER'});
cors({ methods: 'GET,HEAD,PUT,PATCH,POST,DELETE'});

exports.endpoint = function(request, response) {
    let text = '100,000';
    response.writeHead(200, { 'Content-Type': 'text/plain' });
    response.end(text);
}

I am running this on Runkit and still get the error when checking on a website, where I want to display this return value: "No 'Access-Control-Allow-Origin' header is present on the requested resource" 我正在Runkit上运行此文件,但在要显示此返回值的网站上进行检查时仍然出现错误:“所请求的资源上没有'Access-Control-Allow-Origin'标头”

In your example you've loaded the cors module and configured it, but not actually done anything to get it to intercept the HTTP request and send back your CORS headers. 在您的示例中,您已经加载了cors模块并对其进行了配置,但实际上并未做任何事情来使其拦截HTTP请求并发送回CORS标头。

If you're just using a simple Runkit endpoint, you don't need the CORS module at all – just add the headers in your endpoint, where you're already adding the Content-Type header: 如果您仅使用一个简单的Runkit端点,则根本不需要CORS模块-只需在已添加Content-Type头的端点中添加头即可:

exports.endpoint = function(req, res) {
    res.writeHead(200, {
        'Content-Type': 'application/json',
        'Access-Control-Allow-Origin': '*',
        'Access-Control-Allow-Methods': '*',
    });
    res.end('foo');
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在本地主机上的请求资源上不存在“ Access-Control-Allow-Origin”标头 - No 'Access-Control-Allow-Origin' header is present on the requested resource on localhost No 'Access-Control-Allow-Origin' header is present on the requested resource error - No 'Access-Control-Allow-Origin' header is present on the requested resource error Phonegap请求的资源上没有“Access-Control-Allow-Origin”标头。 因此不允许原点&#39;null&#39;访问 - Phonegap No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access XMLHttpRequest无法加载[archivo]。 所请求的资源上没有“ Access-Control-Allow-Origin”标头。 起源[dominio] - XMLHttpRequest cannot load [archivo]. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin [dominio] 出现错误无法加载资源:请求的资源上不存在“ Access-Control-Allow-Origin”标头 - getting error Failed to load resource: No 'Access-Control-Allow-Origin' header is present on the requested resource XMLHttpRequest无法加载 <instagram OEMBED URL> 。 请求的资源上不存在“ Access-Control-Allow-Origin”标头 - XMLHttpRequest cannot load <instagram OEMBED URL>. No 'Access-Control-Allow-Origin' header is present on the requested resource 所请求的资源上没有“ Access-Control-Allow-Origin”标头。 AngularJS - No 'Access-Control-Allow-Origin' header is present on the requested resource. AngularJS 使用json和jquery的请求资源错误中不存在“ Access-Control-allow-origin”标头 - No 'Access-control-allow-origin' header is present on the requested resource error with json and jquery “向Jawbone UP API发送请求时,”请求的资源上没有&#39;Access-Control-Allow-Origin&#39;标头“错误 - “No 'Access-Control-Allow-Origin' header is present on the requested resource” error when sending request to Jawbone UP API Django应用程序中的请求资源上不存在“ Access-Control-Allow-Origin”标头 - No 'Access-Control-Allow-Origin' header is present on the requested resource in Django application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM