# How to contribute

Substats is a serverless function deployed on Cloudflare Workers. You should use wrangler to build, debug and preview the project. More information: Cloudflare Workers | Quick Start.

# Setting up the project

🚥 Note

You'll need global access to CLI tools installed by yarn, so you should add yarn's global binary installation path to your $PATH.

yarn global bin

You can run the command directly to find the /bin's path.

Install wrangler globally:

yarn global add @cloudflare/wrangler

Install dependencies:

yarn

# Familiarizing the structure

The core API backend and the documentations share the same mono-repo. The structure of the project is shown below.

. 📖 Documentation section ├── docs (Documentation, built with VuePress) │   └── …… │ 🚡 API backend ├── src │ ├── index.js (API starting point) │ └── utils (Utility scripts folder) │   └── handlerImporter.js (Imports all API handlers from below) │ 🔑 API handlers │ └── handlers (API integration handlers folder) │            ├── feedly.js (Feedly API integration) │            ├── github.js (GitHub API integration) │            └── …… (You get the idea...) │ 🚀 Deployment └── wrangler.toml (Cloudflare worker deployment config)

# Building, preview and debugging

Preview with cloudflareworkers.com:

yarn dev

Lint and automatically fix all fixable JavaScript files with eslint:

yarn lint

Prettify all JavaScript files with prettier:

yarn pretty

# Storing secrets and authenticating

If an API/Service requires authentication, you can store the required token/password/cookie etc., with Cloudflare Worker's secret, i.e., environment variables.

You can create a mock account for your desired service, and authenticate with this account. I strongly discourage you using your personal account for this task. After you implement an auth-required service, you can make a PR and email me the token/password/cookie etc., along with the name of the secret you used. For instance:

Please upload this secret and token! Thanks.

Secret name: YOUR_SERVICE_TOKEN (Actual variable name used inside the worker) Secret token: VGhpcyBpcyBhIHNlY3JldCB0b2tlbiE= (The secret token itself)

I will upload and store this value onto Cloudflare Worker before merging the PR. DO NOT SEND ME YOUR ACTUAL USER ACCOUNT - PASSWORD COMBINATION!

An example is the authentication-required Telegram Bot API that I used when implementing the Telegram Channel/Chat group member API. For details on how to use this secret global variable, see: Environment Variables - Secrets.

# Publishing admin

Publish to Cloudflare Workers:

yarn publish

# Documentations

To contribute on documentations (i.e., this website), you'll need to build using vuepress.

# Live preview docs

yarn docs:dev

# Building the docs

yarn docs:build
Last Updated: 9/23/2020, 6:50:55 AM