This app fetches all your highlights from your Readwise account and uses AI to help you discover related insights in your highlights.
You need to have a Cloudflare Account on the Workers Standard plan.
The reason why you need an account on the Workers Standard plan is that you might run into a "Too many subrequests error" if you run it on the Bundled plan. Cloudflare Workers on the Bundled plan are limited to a maximum of 50 subrequests.
-
Create a D1 database to store your highlights
npx wrangler d1 create explorer-database
A database ID will be printed to your console. Replace the
database_id
with that database ID. -
Create a
highlights
table in your database.npx wrangler d1 execute explorer-database --command "CREATE TABLE IF NOT EXISTS highlights (id INTEGER PRIMARY KEY, text TEXT NOT NULL)"
-
Create a vectorize index to store vector embeddings
npx wrangler vectorize create explorer-index --dimensions=768 --metric=cosine
-
Install dependencies in the React Project
npm install
Run this in the root directory of the project
-
Enter the
worker
directory and install dependencies for developing Cloudflare workerscd worker npm install
-
Start a remote workers development server on port
3333
npx wrangler dev --port 3333 --remote
The
--remote
flag is important, as AI features that are essential for this app to work are not available when the development server is running locally.Make sure to run this from inside the
worker
directory.It is important to explicitly select a port where the Cloudflare worker will be served, as we make use of
http-proxy-middleware
in the React project to forward requests to/api
to the Cloudflare worker. If you select a port other than3333
, make sure to update it insrc/setupProxy.js
. -
Start a React Development server
npm start
-
Visit
http://localhost:3000
to view the running application.
-
Build the React application
npm run build
-
Copy the built assets into
/worker/build
cp -r build worker/
-
Enter the
worker
directory and deploy the workercd worker npx wrangler deploy
This deploys the worker and assets to Cloudflare.
Keep in mind that after your publish your worker, all your highlights will be public. If you want to restrict access to your Cloudflare Worker, you have to deploy your worker to a custom domain and use Cloudflare Access to restrict access to the application.
Run the following commands to empty your database and reset your vectorize index.
-
Delete all entries from the highlights table.
npx wrangler d1 execute explorer-database --command "DELETE from highlights"
-
Delete the
explorer-index
Vectorize indexnpx wrangler vectorize delete explorer-index
-
Recreate the Vectorize index
npx wrangler vectorize create explorer-index --dimensions=768 --metric=cosine
You will now have an empty highlights table and an empty Vectorize index, and everything should be back to default.
- (Optional) If you already deployed your worker, you will have to redeploy it.
cd worker npx wrangler deploy
- Building a multi-tenant version of this that can store multiple users' highlights.
- Continously syncing highlights from Readwise, rather than only syncing the first time one uses it.
- Writing a GitHub CI workflow that automatically deploys the Worker to Cloudflare on push to GitHub.