fix: remove bad URL constructor

This commit is contained in:
2024-03-04 13:09:09 +00:00
parent 6785ef72e1
commit 99b4d01ff7
5 changed files with 61 additions and 26 deletions

View File

@ -6,26 +6,23 @@ Worker relay is a Nostr relay built on `sqlite-wasm`
`sqlite-wasm` uses OFPS in order to persist the database.
OPFS requires special headers to be present when serving your application. Read more about it [here](https://sqlite.org/wasm/doc/trunk/persistence.md#opfs)
```
Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp
```
### Usage (Vite)
```typescript
import WorkerRelayPath from "@snort/worker-relay/dist/worker?worker&url";
```
### Example
```typescript
const relay = new WorkerRelayInterface(WorkerRelayPath);
import { WorkerRelayInterface } from "@snort/worker-relay";
// in debug mode you may need this, to map to the correct sqlite-wasm path
// this is needed because sqlite-wasm will otherwise look inside @snort/worker-relay directory for sqlite3.wasm
const basePath = new URL("@sqlite.org/sqlite-wasm", import.meta.url);
// internally we resolve the script path like this:
const scriptPath = new URL("@snort/worker-relay/dist/esm/worker.mjs", import.meta.url);
// scriptPath & basePath are optional
const relay = new WorkerRelayInterface(scriptPath.href, basePath.href);
// load sqlite database and run migrations
await relay.init();
await relay.init("my-relay.db");
// Query worker relay with regular nostr REQ command
const results = await relay.query(["REQ", "1", { kinds: [1], limit: 10 }]);
@ -33,7 +30,9 @@ const results = await relay.query(["REQ", "1", { kinds: [1], limit: 10 }]);
// publish a new event to the relay
const myEvent = {
kind: 1,
created_at: Math.floor(new Date().getTime() / 1000),
content: "test",
tags: []
};
if (await relay.event(myEvent)) {
console.log("Success");