Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save r01010010/2de389fe01c9b4e0f17294b7de02c056 to your computer and use it in GitHub Desktop.
Save r01010010/2de389fe01c9b4e0f17294b7de02c056 to your computer and use it in GitHub Desktop.
// frontend
import { DeepstreamClient } from "@deepstream/client";
const client = new DeepstreamClient("localhost:6020");
client.login();
client.on("connectionStateChanged", (connectionState) => {
if (connectionState === "OPEN") {
const record = client.record.getRecord("sincrypto/users.01");
record.whenReady((record) => {
record.set("foo1", "bar");
record.set("foo2", "lol", (err) => {
if (err) {
console.log("Record set with error:", err);
} else {
console.log("Record set without error");
}
});
record.set("foo3", [1, 2, 3, "yikes"]);
});
}
});
// server
const { Deepstream } = require('@deepstream/server')
const server = new Deepstream({
serverName: '9ea87b69-4d52-405f-b1be-1c4debc211ad',
showLogo: true,
dependencyInitializationTimeout: 2000,
exitOnFatalError: false,
storage: {
name: 'mongodb',
options: {
connectionString: 'mongodb+srv://url',
// # optional database name, defaults to `deepstream`
database: 'dbname',
// # optional table name for records without a splitChar
// # defaults to deepstream_docs
defaultTable: 'tablename',
// # optional character that's used as part of the
// # record names to split it into a tabel and an id part
splitChar: '/'
}
},
auth: {
type: 'http',
options: {
endpointUrl: 'https://someurl.com/auth-user',
permittedStatusCodes: [200],
requestTimeout: 2000,
retryStatusCodes: [404, 504],
retryAttempts: 3,
retryInterval: 5000,
reportInvalidParameters: true //# return when credentials are incorrect: missing username or password
}}
})
server.start()
// package.json
"@deepstream/client": "^5.2.5",
"@deepstream/server": "^5.2.4",
"@deepstream/storage-mongodb": "^2.0.2",
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment