gpt4 book ai didi

javascript - Cycle.js 如何启用 Access-Control-Allow-Origin (CORS)

转载 作者:行者123 更新时间:2023-12-03 00:22:32 25 4
gpt4 key购买 nike

正在尝试 CycleJS javascript 响应式(Reactive)框架,我是该范例的新手。

我已经设置了一个流来从外部 URL (en.wikipedia.org) 读取数据并获得以下结果:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://en.wikipedia.org/w/api.php?action=query&list=search&format=json&srsearch=. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing)

我明白为什么返回错误了。在本例中,服务器节点未设置 header

access-control-allow-origin: *

Content-Type: application/json; charset=utf-8

将需要应用 CORS 约束。

我无法找到节点服务器在何处、如何或是否添加 CORS header 。节点 Server.js 代码可以执行此操作,但我需要帮助来触发添加 CORS header 。

谢谢。

package.json 是:

{
"name": "wikipedia",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "parcel -p 1235 index.html",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "cb",
"license": "ISC",
"dependencies": {
"@cycle/dom": "^22.3.0",
"@cycle/http": "^15.1.0",
"@cycle/run": "^5.2.0",
"npm": "^6.6.0",
"xstream": "^11.10.0"
},
"devDependencies": {}
}

是否安装节点包cors没有区别。

我的标题是:

=== Response headers (1.424 KB)  ===
accept-ranges: bytes
age: 0
backend-timing: D=149145 t=1547782329117450
cache-control: private, must-revalidate, max-age=0
content-disposition: inline; filename=api-result.json
content-encoding: gzip
content-length: 1409
content-type: application/json; charset=utf-8
date: Fri, 18 Jan 2019 03:32:09 GMT
p3p: CP="This is not a P3P policy! …lAutoLogin/P3P for more info."
server: mw1224.eqiad.wmnet
server-timing: cache;desc="pass"
set-cookie: WMF-Last-Access=18-Jan-2019;Pa…Tue, 19 Feb 2019 00:00:00 GMT
set-cookie: WMF-Last-Access-Global=18-Jan-…Tue, 19 Feb 2019 00:00:00 GMT
strict-transport-security: max-age=106384710; includeSubDomains; preload
vary: Accept-Encoding,Treat-as-Untru…,Cookie,Authorization,X-Seven
via: 1.1 varnish (Varnish/5.1), 1.1…1), 1.1 varnish (Varnish/5.1)
x-analytics: ns=-1;special=Badtitle;https=1;nocookies=1
x-cache: cp1079 pass, cp2012 pass, cp5007 pass, cp5008 pass
x-cache-status: pass
x-content-type-options: nosniff
X-Firefox-Spdy: h2
x-frame-options: SAMEORIGIN
x-powered-by: HHVM/3.18.6-dev
x-search-id: cfqpbykh6k905h7hol9taip2o
x-varnish: 494419235, 536993066, 474976751, 593813616


=== Request headers (362 B) ===
Accept: */*
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.5
Connection: keep-alive
Host: en.wikipedia.org
Origin: http://localhost:1235
Referer: http://localhost:1235/
TE: Trailers
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linu…) Gecko/20100101 Firefox/64.0

最佳答案

感谢您为我指明了维基百科阻止该请求的正确方向。经过进一步研究,解决方案非常简单。将“&origin=*”添加到请求字符串中,Wikipedia 将返回 CORS 策略。就是这样。

关于javascript - Cycle.js 如何启用 Access-Control-Allow-Origin (CORS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54247474/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com