Giter VIP home page Giter VIP logo

cloudflare-edge-leaderboard's Introduction

cloudflare-edge-leaderboard

A simple leaderboard implementation that can be easily applied to existing projects to report scores

Step 1: Fork the repo

Use your favorite CLI or Desktop app to fork this repo, and then publish it to GitHub or GitLab (Private or public)

Step 2: Set up a new CloudFlare Pages Project

Click "Connect to Git" and choose your newly cloned project CloudFlare Pages

Step 3: Configure .env.template

  1. Get your account ID and Global API key from: https://dash.cloudflare.com/profile/api-tokens
  2. Update .env.template:
CF_API_KEY=your_cloudflare_api_key
CF_API_EMAIL=your_cloudflare_email
CF_ACCOUNT_ID=your_cloudflare_account_id
CF_API_BASE_URL = "https://api.cloudflare.com/client/v4"
  1. Rename the file to .env
  2. (NOTE!: Add .env to .gitignore, don't expose your CF API key.)

Step 4: Install dependencies

  1. Install NPM dependencies in your project folder with npm install
  2. Run db_setup.js script with node db_setup.js
  3. Run local DB setup with # DB Setup npx wrangler d1 execute edge-leaderboard-db --local --command "CREATE TABLE IF NOT EXISTS leaderboard ( name TEXT PRIMARY KEY, score INTEGER, timestamp TEXT);"
  4. Run npx wrangler pages dev -- npm run dev for local development server.

Step 5: Done!

Now you can simply push your code for auto-deployments to your CloudFlare Pages project. Any js files you put in /functions will be attempted to be hooked as Worker functions, read more about CloudFlare Pages Functions here

(Optional: Wrangler)

You need to modify your wrangler.tom file if this is not done automatically: [[d1_databases]] binding = "DB" # Should match preview_database_id database_name = "YOUR_DB_NAME_HERE" database_id = "YOUR_DATABASE_NAME" # wrangler d1 info YOUR_DATABASE_NAME preview_database_id = "DB" # Required for Pages local development

cloudflare-edge-leaderboard's People

Contributors

mrcsxndr avatar

Stargazers

HeisenBerg? avatar

Watchers

HeisenBerg? avatar  avatar

Forkers

wanghaisheng

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.