drifting-in-space / driftdb Goto Github PK
View Code? Open in Web Editor NEWA real-time data backend for browser-based applications.
Home Page: https://driftdb.com
License: MIT License
A real-time data backend for browser-based applications.
Home Page: https://driftdb.com
License: MIT License
Include that:
$ git clone ...
$ cd driftdb
$ cargo build --release
...
Compiling worker-macros v0.0.6
Compiling worker v0.0.11
Compiling driftdb-server v0.1.1 (/memfs/git/driftdb/driftdb-server)
Compiling driftdb-worker v0.1.1 (/memfs/git/driftdb/driftdb-worker)
error: driftdb-worker should only be compiled to WebAssembly. Use driftdb-server for other targets.
--> driftdb-worker/src/lib.rs:102:1
|
102 | / compile_error!(
103 | | "driftdb-worker should only be compiled to WebAssembly. Use driftdb-server for other targets."
104 | | );
| |_^
error: could not compile `driftdb-worker` due to previous error
warning: build failed, waiting for other jobs to finish...
OS: FreeBSD 13.1-RELEASE-p5
cargo 1.66.1
Currently, shared reducers will advance optimistically on the client side, but slide back as states start coming in from the server.
Instead, we should:
Safe mode can be enabled in js-pkg/apps/demos/next.config.js
People want to use DriftDB in non-React environments (Svelte and SolidJS so far). We should:
From SyncLinear.com | DIS-610
I had signed up a api token for testing DriftDB, it's really wonderful product.
But in the network dev-tool, we can see the api token, And anyone can use it.
Is there some way to protect the token?
Thanks.
$ xh post http://localhost:8080/new
HTTP/1.1 405 Method Not Allowed
Allow: GET,HEAD
Content-Length: 0
Date: Sat, 04 Feb 2023 13:31:05 GMT
$ ./driftdb-server
2023-02-04T13:31:05.110411Z INFO request{method=POST uri=/new version=HTTP/1.1}: tower_http::trace::on_response: finished processing request latency=0 ms status=405
According to the docs:
Create a room by sending a POST request to /new. It returns a JSON object with the following fields:
room: random string uniqely representing the new room (string).
socket_url: WebSocket URL to connect to the room for real-time reads and write (string).
http_url: HTTP URL to send messages to the room from non-WebSocket clients (string).
Given a room ID returned by /new, you can receive the same JSON object by sending a GET request to /room/<ROOM_ID>.
useSharedState
should allow a function to be passed instead of a literal value. The function is evaluated on the current (local) value of the state.useSharedReducer
should take an optional init
function that takes the prior argument and returns the first state.The functions will still differ from their React counterparts in that they will take a key as the first parameter.
Currently it is hard coded to compact after 5 messages, which was chosen for demonstration. We should increase the default and make it configurable.
Trying to setup a local installation of driftdb-server, I've managed to connect the ui.driftdb.com to the local server but failed to send a POST request to the http_url
as described in the documentation.
Although I'm new to rust, just reviewing https://github.com/drifting-in-space/driftdb/blob/main/driftdb-server/src/server.rs#L207-L212 I understand that there is no route POST /room/:room_id/send
in the code.
#52 does not properly work if driftdb-server and clients are in different domains. Steps to reproduce:
fetch('http://localhost:3000/new', {method:"post"}).then((response) => response.json()).then((data) => console.log(data))
https://ui.driftdb.com/?url=ws://localhost:3000/room/<UUID from previous step>/connect
in a new tab --> connects to the room.fetch('http://localhost:3000/room/<UUID from previous step>/send', {method:"post", mode: "cors", body: JSON.stringify({
"action": {"type": "append"},
"key": "slider",
"type": "push",
"value": 55
})}).catch((error) => console.dir(error))
Result
POST http://localhost:3000/room/28573b90-a80c-4369-a2fa-c809c440a9d5/send 415 (Unsupported Media Type)
(anonymous) @ VM65:1
fetch('http://localhost:3000/room/28573b90-a80c-4369-a2fa-c809c440a9d5/send', {method:"post", mode: "cors", headers: { 'Content-Type': "application/json"}, body: JSON.stringify({
"action": {"type": "append"},
"key": "slider",
"type": "push",
"value": 55
})}).catch((error) => console.dir(error))
Result
Access to fetch at 'http://localhost:3000/room/28573b90-a80c-4369-a2fa-c809c440a9d5/send' from origin 'https://driftdb.com' has been blocked by CORS policy: Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response.
Not confident to submit a PR, but tried the following and seems to work:
diff --git a/Cargo.lock b/Cargo.lock
index 2af49be..546c066 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -281,6 +281,7 @@ dependencies = [
"clap",
"dashmap",
"driftdb",
+ "http",
"hyper",
"serde",
"serde_json",
@@ -462,9 +463,9 @@ dependencies = [
[[package]]
name = "http"
-version = "0.2.8"
+version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399"
+checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482"
dependencies = [
"bytes",
"fnv",
diff --git a/driftdb-server/Cargo.toml b/driftdb-server/Cargo.toml
index 96b4bd2..e22dd10 100644
--- a/driftdb-server/Cargo.toml
+++ b/driftdb-server/Cargo.toml
@@ -23,3 +23,4 @@ tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }
driftdb = {path = "../driftdb", version="0.1.0"}
dashmap = "5.4.0"
uuid = { version = "1.3.0", features = ["v4"] }
+http = "0.2.9"
diff --git a/driftdb-server/src/server.rs b/driftdb-server/src/server.rs
index 7d37dd2..f9890aa 100644
--- a/driftdb-server/src/server.rs
+++ b/driftdb-server/src/server.rs
@@ -16,6 +16,7 @@ use tower_http::{
cors::{AllowOrigin, CorsLayer},
trace::{DefaultMakeSpan, DefaultOnRequest, DefaultOnResponse, TraceLayer},
};
+use http::header::{CONTENT_TYPE};
use tracing::Level;
use uuid::Uuid;
@@ -213,7 +214,8 @@ impl RoomResult {
pub fn api_routes() -> Result<Router> {
let cors = CorsLayer::new()
- .allow_methods([Method::GET])
+ .allow_methods([Method::GET, Method::POST])
+ .allow_headers([CONTENT_TYPE])
.allow_origin(AllowOrigin::any());
let room_map = RoomMap::new();
Hi,
I'm a Cybersecurity researcher developing Packj [1]. Our tool has detected a supply-chain vulnerability in this repository. In order for me to disclose it, kindly enable GitHub Private vulnerability reporting, which allows security research to responsibly disclose a security vulnerability.
Thanks!
Packj detects malicious/"risky" NPM/PyPI/Ruby dependencies: https://github.com/ossillate-inc/packj
All the docs use React, but how would one use driftdb without a view library like react, simply using vanilla JS?
Please include some documentation for users who don't want to use Meta flux and related tools
Wait until the dispatch function has not been called for (say) 100ms before attempting a rollup.
Only do a rollup if the size passes the threshold as of the last message sent by DriftDB.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.