Skip to content

jsbenchmark/jsbm.dev

Repository files navigation

jsbm.dev

Benchmark storage and redirecting Cloudflare Worker for JSBenchmark.com

API

GET /:shortcode

Redirects to the benchmark with the given shortcode.

Examples:

POST /api/shortcode

Creates a new shortcode for the provided benchmark state. Must match the structure of a Benchmark or Repl state (see below).

Benchmark
interface BenchmarkState {
  cases: {
    id: string;
    code: string;
    name: string;
  }[];
  config: {
    name: string;
    parallel: boolean;
    globalTestConfig: {
      dependencies: {
        url: string;
        name: string;
        esm: boolean;
      }[];
    };
    dataCode: string;
  };
}
Repl
interface ReplState {
  config: {
    name: string;
    test: {
      dependencies: {
        url: string;
        name: string;
        esm: boolean;
      }[];
      code: string;
    };
  };
}

Response

{ "code": "2bEXvzJfZWuvetvRdkEUXwOkCVd" }
Field Type Description
code string The shortcode for the benchmark.

Development

To get up-and-running in development, do the following:

  1. Setup Wrangler

I use Volta but npm i -g works just as well.

$ volta install wrangler # or
$ npm i -g wrangler

Then, run wrangler login and follow the instructions.

  1. Clone .dev.vars

The example file is prefixed with an underscore.

$ cp _.dev.vars .dev.vars
  1. Start postgres (and pgbouncer)

Run docker compose up --wait to start postgres and pgbouncer. Pgbouncer is used to pool connections to the database, which is required for serverless. The migrations are ran automatically.

Neon, the database provider this project recommends in production, has a native pooling option, so this is only required for development.

Deployment

To deploy this project, do the following:

  1. Create a database

...on https://neon.tech. Make sure you their pooling for serverless option. Then, go to the SQL Editor tab and add the migrations in order from the migrations folder.

Then, deconstruct the database URL into the following variables. You're gonna need this later. It might be a good idea to do this in .dev.vars and comment out each line -- just so you have somewhere to copy and paste from.

# PG_USER = ""
# PG_PASSWORD = ""
# PG_HOST = ""
# PG_DATABASE = ""
  1. Deploy the worker
$ wrangler login # login to Cloudflare
$ wrangler deploy # deploy the worker
# for each key and value of PG_*, run the following command
# you can also do this on the Worker dashboard,
# but remember to click Entrypt!
$ wrangler secret put <key> # will open a prompt for the value
  1. Profit.

Now, you can create your own shortcodes with the API Documentation above.

You can test the worker by visiting the shortcode default.

About

Benchmark storage and redirecting Cloudflare Worker for JSBenchmark.com

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages