简体   繁体   English

无法通过JavaScript中的$ post在neo4j中创建索引

[英]Can't create index in neo4j via $post in javascript

I create simple web app, using neo4j REST API, JS and JQuery. 我使用neo4j REST API,JS和JQuery创建简单的Web应用程序。 I am able to create new node using $post : 我可以使用$post创建新节点:

$.post("http://localhost:7474/db/data/node",
{
    "name":data[i].name,
    "phone":data[i].phone
},  
function(jsonData) {
    newlyCreated = jsonData.self;
},
'json');

it works, new node is created and appears in db. 它有效,创建了新节点并显示在db中。

Unfortunately when I try to create index using $post , this syntax doesn't work: 不幸的是,当我尝试使用$post创建索引时,此语法不起作用:

$.post("http://localhost:7474/db/data/index/node",{"name":"phone"},function(indexInfo) {
        console.log(indexInfo);
}, 'json');

When I try to use neo4j http console: 当我尝试使用neo4j http控制台时:

POST http://localhost:7474/db/data/index/node/ {"name": "phone"}

It works fine index is created. 它工作良好,索引创建成功。

Any suggestions why $.post doesn't work properly in this case? 有什么建议为什么$.post在这种情况下不能正常工作?

It's a no-no to send requests to Neo4j directly through JavaScript. 直接通过JavaScript将请求发送到Neo4j是不可以的。 Probably it doesn't work because of the Cross Origin ( No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'xxyy' is therefore not allowed access). 可能由于交叉原点而无法正常工作(所请求的资源上没有“ Access-Control-Allow-Origin”标头。因此,不允许原点“ xxyy”访问)。

Usually Neo4j runs on port 7474, so if you're doing requests from port 80 (default http port) you're no allowed. 通常Neo4j运行在端口7474上,因此,如果您正在从端口80(默认的http端口)发出请求,则不允许这样做。 Also, if you make request from the same port (like the browser does, you also need to add Authentication is that is enabled in your Neo4j configuration) 另外,如果您从同一端口发出请求(就像浏览器一样,您还需要添加在Neo4j配置中启用的身份验证)

The security risk is that if you do direct request from a browser to a secure Neo4j, saving username and password in the browser will let anyone have direct access to your Neo4j instance. 安全风险是,如果您确实从浏览器直接向安全的Neo4j请求,则在浏览器中保存用户名和密码将使任何人都可以直接访问您的Neo4j实例。

So the best way is to create a proxy (with a Allow Origin configuration), that verify the request and if it's a valid one, authenticate and send it to the database, and return to the browser request the required data. 因此,最好的方法是创建一个代理(具有“允许来源”配置),以验证请求以及请求是否有效,进行身份验证并将其发送到数据库,然后返回浏览器请求所需的数据。 :) :)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM