【发布时间】:2020-06-01 16:55:37
【问题描述】:
对于这样一个基本问题,我深表歉意,但我似乎无法弄清楚如何做到这一点,并且文档都非常具体。
我只是想使用 gremlin 连接到标准 Gremlin DB (Cosmos)。它在服务器上运行良好,但是当我从浏览器连接时,出现此错误:
Error: ws does not work in the browser. Browser clients must use the native WebSocket object
没有什么特别复杂的,而且错误似乎很明显。
代码如下:
constructor() {
var authenticator = new Gremlin.driver.auth.PlainTextSaslAuthenticator(`/dbs/${config.database}/colls/${config.collection}`, config.primaryKey);
this.gremlin_config_options = {
authenticator,
traversalsource: "g",
rejectUnauthorized: true,
mimeType: "application/vnd.gremlin-v2.0+json"
}
var DriverRemoteConnection = Gremlin.driver.DriverRemoteConnection;
this.Graph = Gremlin.structure.Graph;
var dc = new DriverRemoteConnection(this.gremlin_websocket,this.gremlin_config_options);
this.graph = new this.Graph();
this.g = this.graph.traversal().withRemote(this.gremlin_websocket);
};
当我执行以下代码时,它会在没有 Javascript 错误的情况下完成。
constructor() {
var authenticator = new Gremlin.driver.auth.PlainTextSaslAuthenticator(`/dbs/${config.database}/colls/${config.collection}`, config.primaryKey);
this.gremlin_config_options = {
authenticator,
traversalsource: "g",
rejectUnauthorized: true,
mimeType: "application/vnd.gremlin-v2.0+json"
}
this.Graph = Gremlin.structure.Graph;
this.gremlin_websocket = new WebSocket('ws://test_db.gremlin.cosmos.azure.com:8182/')
this.graph = new this.Graph();
this.g = this.graph.traversal().withRemote(this.gremlin_websocket);
};
但是,我需要传递身份验证和收集信息(当前在身份验证器对象中)。但是WebSocket似乎不支持它,Driver Remote Connection似乎并没有原生地接受websocket。我该怎么办?
【问题讨论】:
标签: javascript node.js azure-cosmosdb gremlin