# 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 (opens new window).

# Setting up the project

We strongly recommend you install npm with a Node version manager like n (opens new window) or nvm (opens new window), which will allow wrangler to install configuration data in a global node_modules directory in your user's home directory, without requiring that you run as root.

Once you've installed Node.js with a Node version manager, run the following command to install wrangler globally:

npm i @cloudflare/wrangler -g

Install dependencies:

npm install

# 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) │   └── serviceProviders.js (Imports all service APIs from below) │ 🔑 API Services │ └── services (API integrations for different services) │        ├── 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 (opens new window):

npm run dev

Lint and automatically fix all fixable JavaScript files with eslint:

npm run lint

Prettify all JavaScript files with prettier:

npm run 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 (opens new window) 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 (opens new window).

# Publishing admin

Publish to Cloudflare Workers:

npm run publish

# Documentations

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

# Live preview docs

npm run docs:dev

# Building the docs

npm run docs:build
Last Updated: 1/1/2021, 8:31:31 AM