SQL Gateway Worker Prototype
This worker will log all user agents that access each route the worker is enabled on. These statistics can be viewed by appending /stat
to the route you want to view statistics for.
For instance, if you wanted to get the user agent statistics for https://example.org/stat
, you would go to https://example.org/stat
Usage
To compile this worker, clone the repository, run npm install
followed by npm run build
, and put the output from the target
directory in the worker console. This worker is subdomain agnostic, so if you want to enable it across the entire site, set the route to *example.com/*
You can preview what the worker would look like by running npm run preview
or npm run preview -- --preview-url https://example.com
Development
If you would like to develop your own database application, you can take the source from db.js
and use it however you would like. The procedure for connecting to an existing database can be found here. db.js
exposes a simple execute function that takes a SQL query as its sole parameter. As the Gateway backend becomes more stable we will support parameters, but for now it's recommended to construct query strings and take care of sanitization yourself.
Intricacies
This worker excludes any route behind a /static
path, and the /stat
routes are not logged for obvious reasons.
The new Cloudflared feature exposes an endpoint that allows an authenticated user to execute arbitrary SQL.
Existing Demo
There's a resource leaking bug with the database connection, so it may go up and down periodically. You can check to see if it's working at ahrenn.me
. It may go up and down periodically as I work on other workers and if either the db instance or the tunnel instance go down.
This will work on any domain, you can try it out for yourself, it'll commit to the same database that hosts the user agent info for any other site using this worker. You also have read/write access to the db with the credentials I've committed to the database, please play nice :)