简体   繁体   English

如何允许访问其他端口?

[英]How to permit access to a different port?

The Amber Smalltalk IDE works with a server written in nodejs. Amber Smalltalk IDE可与用nodejs编写的服务器一起使用。 How can I configure the server that XMLHttpRequests going to a different port of the same domain are allowed? 如何配置允许XMLHttpRequests进入同一域的不同端口的服务器?

The default access to Amber is 琥珀色的默认访问权限是

http://127.0.0.1:4000/

And to retrieve and store JSON data I want to use a couchDB instance (default port is 5984) 并要检索和存储JSON数据,我想使用ouchDB实例(默认端口为5984)

 | req | req := XMLHttpRequest new. req open: 'GET' url: 'http://127.0.0.1:5984/' asynchronous: false. req send: ''. 

The problem 问题

Access is not possible because of cross-domain access policy. 由于跨域访问策略,因此无法访问。

Notes 笔记

The server is called from 服务器从

amber-master\bin\server.bat

The server is in 服务器在

amber-master\cli\js\amber-cli.js

The client is Firefox which should allow that the XMLHttpRequest objects may access a different port provided the server indicates this with an 'Access-Control-Allow-Origin header'. 客户端是Firefox,它应该允许XMLHttpRequest对象可以访问其他端口,前提是服务器使用“ Access-Control-Allow-Origin标头”进行指示。

References 参考

http://www.w3.org/TR/cors/#access-control-allow-origin-response-header http://www.w3.org/TR/cors/#access-control-allow-origin-response-header

CouchDB cross-domain access from XMLHttpRequest? 来自XMLHttpRequest的CouchDB跨域访问?

After answer by MKroenert 在MKroenert回答之后

I upgraded to version 1.4.0 of CouchDB and adapted the local.ini file to allow for CORS (C:\\Program Files\\Apache Software Foundation\\CouchDB\\etc\\couchdb\\local.ini) 我升级到1.4.0版的CouchDB,并修改了local.ini文件以允许CORS(C:\\ Program Files \\ Apache Software Foundation \\ CouchDB \\ etc \\ couchdb \\ local.ini)

[httpd]
enable_cors = true

[cors]
origins = *

More on http://wiki.apache.org/couchdb/CORS In particular how to limit access. 有关http://wiki.apache.org/couchdb/CORS的更多信息,特别是如何限制访问。

3.12.1. 3.12.1。 Enabling CORS http://docs.couchdb.org/en/latest/configuring.html 启用CORS http://docs.couchdb.org/en/latest/configuring.html

Then after restarting the couchDB service the following code snippet works fine in an Amber Smalltalk workspace 然后,在重新启动CouchDB服务之后,以下代码段在Amber Smalltalk工作区中可以正常工作

| req colordict mimeType |
colordict := HashedCollection new.

colordict at: 'red' put: 'rot'.
colordict at: 'blue' put: 'blau'.
colordict at: 'yellow' put: 'gelb'.

req := XMLHttpRequest new.
req open: 'PUT' 
    url: 'http://localhost:5984/components/test2' asynchronous: false.

mimeType :='application/json'.

req setRequestHeader:  'Content-Type'  mimeType: mimeType. 
req send: (JSON stringify: colordict).
req responseText  

A 'printit' gives back “ printit”回馈

'{"ok":true,"id":"test2","rev":"1-8d2356ebdbabdd87a35e0ae3b137bdb5"}
' 

If I understand your problem correctly you try to access a resource on 127.0.0.1:5984 from within an Amber program. 如果我正确理解了您的问题,则尝试从Amber程序中访问127.0.0.1:5984上的资源。

Since it is not mentioned in the question there are two possible cases in this question: 由于问题中未提及,因此该问题有两种可能的情况:

  1. A non Amber server is running on port 5984 . 非琥珀色服务器正在端口5984上运行。

    In this case it is the responsibility of the specific server running on port 5984 to provide the Access-Control-Allow-Origin: * header and is not a problem with the Amber server. 在这种情况下,端口5984上运行的特定服务器有责任提供Access-Control-Allow-Origin: *标头,而Amber服务器则不成问题。

  2. Another Amber server is running on port 5984 . 另一台Amber服务器正在端口5984上运行。

    In this case we do not currently implement sending the Access-Control-Allow-Origin: * header. 在这种情况下,我们当前不实现发送Access-Control-Allow-Origin: *标头。 The Amber server is meant to be a simple development server and should not be used for deployment. Amber服务器是作为简单的开发服务器,不应用于部署。

However, if there is a specific use-case where sending this header is necessary we can discuss this on the Amber mailinglist or create an issue on the GitHub tracker and mark it as a feature request. 但是,如果有特定的用例需要发送此标头,我们可以在Amber邮件列表上进行讨论,或在GitHub跟踪器上创建问题,并将其标记为功能请求。

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

相关问题 如何解决requirejs许可错误 - how to solve requirejs permit error 如何在不同的端口运行反应端口和后端端口? - How to run react port and backend port in different ports? 如何访问Heroku客户端的环境端口? - How to access the environment PORT on client side in Heroku? 如何在不同的端口运行节点应用程序 - 暂时? - How to run the node app in different port - as temporarily? 如何使用不同的端口部署多个nodeJS应用程序 - How to deploy multiple nodeJS application with different port 如何将不同端口上的前端应用程序与后端连接? - How to connect a frontend application on a different port with a backend? 如何在同一个端口上运行不同的服务器? - How to run different server on same port? 如何将在不同端口上运行的Node.js与在不同端口上运行的Vue.js完全集成在一起? - How to integrate Node.js running on different port with Vue.js running on a different port altogether? 不同端口上的套接字服务器和不同端口上的客户端 - Socket server on different port and Client on different port 我们如何在 Laravel 控制器中使用端口号调用 url()。 节点服务器在 8001 和 Laravel 端口是 8000 的不同端口上运行? - How can we call url() with port number in Laravel controller. Node server is running on different port that 8001 and Laravel port is 8000?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM