Skip to content

Commit cb66f2c

Browse files
authored
updated browser example (#52)
1 parent 11e4cf3 commit cb66f2c

File tree

7 files changed

+60
-58
lines changed

7 files changed

+60
-58
lines changed

examples/browser/README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ in the main `README.md` for more information common to non-standard environments
3232

3333
3. Copy the `.env.example` file to `.env` and fill in the required values.
3434

35-
4. Run `npm run dev` to start the local development server.
35+
4. Visit https://cors-anywhere.herokuapp.com/corsdemo to temporarily enable access to the demo server.
3636

37-
5. Visit `http://localhost:5173` in your browser to see the example in action.
37+
5. Run `npm run dev` to start the local development server.
38+
39+
6. Visit `http://localhost:5173` in your browser to see the example in action.
3840

3941
### Steps to Start Your Own Project:
4042

@@ -44,8 +46,8 @@ in the main `README.md` for more information common to non-standard environments
4446

4547
3. Install the `events` polyfill (if your build tool doesn't provide polyfills) by running `npm i events`.
4648

47-
4. Set up a CORS proxy to forward requests to the Data API. You can use [cors-anywhere](https://github.com/Rob--W/cors-anywhere),
48-
or any other CORS proxy of your choice.
49+
4. Set up a CORS proxy to forward requests to the Data API. You can use something like [cors-anywhere](https://github.com/Rob--W/cors-anywhere),
50+
[corsproxy.io](https://corsproxy.io/), or any other CORS proxy of your choice.
4951

5052
5. When doing `client.db()`, prefix the endpoint URL with the CORS proxy URL as appropriate.
5153

examples/browser/package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/browser/src/main.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import './style.css'
22
import { DataAPIClient } from '@datastax/astra-db-ts';
33

4-
const client = new DataAPIClient(import.meta.env.VITE_ASTRA_DB_TOKEN);
5-
const db = client.db(`https://corsproxy.io/?${import.meta.env.VITE_ASTRA_DB_ENDPOINT}`);
4+
const client = new DataAPIClient(import.meta.env.VITE_ASTRA_DB_TOKEN, {
5+
httpOptions: { client: 'fetch' }
6+
});
7+
const db = client.db(`https://cors-anywhere.herokuapp.com/${import.meta.env.VITE_ASTRA_DB_ENDPOINT}`);
68

79
const app = document.querySelector<HTMLDivElement>('#app')!;
810
app.innerHTML = '<p>Loading...</p>';

examples/cloudflare-workers/package-lock.json

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/http2-when-minified/package-lock.json

Lines changed: 7 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/update-example-client-dep.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
cwd=$(pwd)
2+
3+
case $1 in
4+
npm)
5+
for dir in examples/*; do
6+
cd "$cwd/$dir" || exit 1
7+
npm rm @datastax/astra-db-ts
8+
npm i @datastax/astra-db-ts
9+
done
10+
;;
11+
local)
12+
tarball_dir=$(pwd)
13+
14+
npm run build
15+
npm pack
16+
17+
for dir in examples/*; do
18+
cd "$cwd/$dir" || exit 1
19+
npm i "${tarball_dir}"/datastax-astra-db-ts-*.tgz
20+
npm i @datastax/astra-db-ts
21+
done
22+
23+
rm "${tarball_dir}"/datastax-astra-db-ts-*.tgz
24+
;;
25+
*)
26+
echo 'Invalid args-must pass either "npm" or "local"'
27+
;;
28+
esac

src/data-api/ids.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ export class ObjectId {
295295
}
296296

297297
const MACHINE_ID = ~~(Math.random() * 0xFFFFFF);
298-
const PID = ((typeof process?.pid !== 'number') ? ~~(Math.random() * 100000) : process.pid) % 0xFFFF;
298+
const PID = ((typeof process === 'undefined' || typeof process.pid !== 'number') ? ~~(Math.random() * 100000) : process.pid) % 0xFFFF;
299299

300300
const hexTable = Array.from({ length: 256 }, (_, i) => {
301301
return (i <= 15 ? '0' : '') + i.toString(16);

0 commit comments

Comments
 (0)