Skip to content

windybirth/firebase

 
 

Repository files navigation

windy10v10ai-cloud

Build Status Deploy Firebase License: MIT CodeFactor
GitHub issues GitHub pull requests GitHub contributors GitHub stars GitHub forks

Backend for Windy 10v10ai with Firebase

Built With

  • Firebase
    • Hosting
    • Functions
    • Firestore Database
  • NextJS

Get Start

Installation

Need

  • Java
  • Node v22
    • Recommend install node use nvm
# set/update node version
nvm install
nvm alias default $(cat .nvmrc)
# firebase setting
npm install -g firebase-tools
firebase login
firebase use windy10v10ai

# setup package
npm install

# web setting
firebase experiments:enable webframeworks

Set GCP

# Setup gcloud authentication (need to do first time)
gcloud auth login
gcloud config set project windy10v10ai

Running the app

Download DB data

# download data from storage
rm -rf firestore-backup
mkdir firestore-backup
gsutil -m cp -r "gs://windy10v10ai.appspot.com/firestore-backup/20250928/*" firestore-backup

Start Firebase Emulator & API & Web

npm run start

API only

# REPL
(cd api && npm run start -- --entryFile repl)

# unit tests
(cd api && npm run test)

# e2e tests (need stop firebase emulator)
(cd api && npm run test:e2e)

Tips: If debug or e2e test not working with address already used error, kill nodejs process by pkill -f node, or try to restart winnat

net stop winnat
net start winnat

Local end points

API Guide

More usage details, including configuration, authentication, and example code, please refer to API Guide.

Maintenance

Deploy

Deploy with Github Action

Github Action will deploy automatically when push to main branch.

  • main: Deploy Firebase Functions and Hosting

Deploy Manually

  • Deploy all
firebase deploy
  • Deploy part
# Deploy specific function
firebase deploy --only functions:client
firebase deploy --only functions:admin
firebase deploy --only functions:scheduledOrderCheck
# Deploy all function
firebase deploy --only functions

# Deploy hosting only
firebase deploy --only hosting
# Deploy function and hosting
firebase deploy --only functions,hosting

Set secret environment variables

  1. Create env in secret manager
  2. Set function run with secrets in index.ts
  3. Use secrets as process.env.SECRET_NAME in code

Allow/Disable unauthenticated HTTP function invocation

https://cloud.google.com/functions/docs/securing/managing-access-iam#allowing_unauthenticated_http_function_invocation

Backup Firestore

https://console.cloud.google.com/firestore/databases/-default-/import-export?project=windy10v10ai

Update dependencies

  • Update package.json
# install tool
`npm install -g npm-check-updates`

# cd to dir
cd api
# update package.json
ncu -u
# update package-lock.json
npm update

Use Admin API

Need

  • gcloud cli

CLI

curl -H "Authorization: bearer $(gcloud auth print-identity-token)" https://asia-northeast1-windy10v10ai.cloudfunctions.net/admin/api

Postman

## Get token
echo $(gcloud auth print-identity-token)

Import api/swagger-spec.yaml to postman with variable baseUrl : https://asia-northeast1-windy10v10ai.cloudfunctions.net/admin

Extension

Export Firestore to Bigquery

Setup Stream Firestore to BigQuery

firebase ext:install firebase/firestore-bigquery-export

or Edit firebase.json and create extensions/firestore-bigquery-export-xxx.env

  "extensions": {
    "firestore-bigquery-export-xxx": "firebase/firestore-bigquery-export@0.1.54"
  }

Deploy Firestore to BigQuery

firebase deploy --only extensions

Import existing documents (need gcp auth)

Guides

Setup gcloud default auth

gcloud auth application-default login

Run import command

sh ./extensions/import-firestore-to-bigquery.sh

Generate schema views

Create schema file table_name_schema.json and run command.

How to create schema file

sh ./extensions/generate-schema-views.sh

About

The backend of dota2 windy10v10ai

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • TypeScript 95.0%
  • CSS 2.5%
  • HTML 1.2%
  • Other 1.3%