diff --git a/pages/client-libraries/javascript.mdx b/pages/client-libraries/javascript.mdx index 6b14f8d7a..18ec08b70 100644 --- a/pages/client-libraries/javascript.mdx +++ b/pages/client-libraries/javascript.mdx @@ -12,11 +12,10 @@ import CodeSnippet from '/components/code-snippet/CodeSnippet' Learn how to create a JavaScript application that connects to the Memgraph database and executes simple queries. -Running queries directly from a web browser is **not -recommended** because of additional requirements and possible -performance issues. In other words, we encourage you to use -server-side libraries and clients for top performance whenever -possible. +Run the driver in a server-side application where you can. A page in a web +browser can connect to Memgraph too, but the database credentials end up in +client-side code, and a page served over HTTPS can't connect directly. See +[Connect from a web browser](#connect-from-a-web-browser). ## Quickstart @@ -291,6 +290,24 @@ Then, you can connect to the database with the following snippet: For more details on how to create user with credentials and set authentication, visit the [Memgraph authentication guide](/database-management/authentication-and-authorization/users#administer-users). +### Connect from a web browser + +In a web browser, the JavaScript driver connects over WebSocket instead of a +TCP socket. Memgraph accepts WebSocket connections on the Bolt port (7687 by +default), so a page served over HTTP connects with the same `bolt://` URI and +code as in [Database connection](#database-connection). + +Memgraph accepts WebSocket connections on the Bolt port only when SSL is +disabled. If Memgraph runs with the `--bolt-cert-file` and `--bolt-key-file` +flags, browser connections fail, because the Bolt port has no secure WebSocket +(`wss://`). Without SSL, the connection is unencrypted (`ws://`), and browsers +block unencrypted WebSocket connections from pages served over HTTPS. + +To query Memgraph from a page served over HTTPS, have the page call your own +backend over HTTPS, and query Memgraph from the backend with the driver. +Keeping Memgraph behind a backend is good practice in any case: the database +credentials stay on the server, and Memgraph isn't reachable from the browser. + ### Query the database After connecting your driver to Memgraph, you can start running queries. diff --git a/pages/database-management/ssl-encryption.mdx b/pages/database-management/ssl-encryption.mdx index 05c48a53d..8c978cc4a 100644 --- a/pages/database-management/ssl-encryption.mdx +++ b/pages/database-management/ssl-encryption.mdx @@ -141,7 +141,14 @@ SSLMode::Require` to the `ConnectParams`. -WebSocket over SSL is currently not supported in Memgraph. +When SSL is enabled, the Bolt port doesn't accept WebSocket connections, so +JavaScript applications in a web browser can't connect over secure WebSocket +(`wss://`). To query Memgraph from a page served over HTTPS, see [Connect from +a web browser](/client-libraries/javascript#connect-from-a-web-browser). + +The [log WebSocket server](/database-management/monitoring#real-time-logs-tracking-via-websocket-server) +on port 7444 uses the same certificate. When SSL is enabled, connect to it +with `wss://`.