Add scaffolding to point dev server at local functions

This commit is contained in:
Marshall Polaris 2022-07-18 01:20:20 -07:00
parent f58801d4f1
commit 908917e4d9
4 changed files with 31 additions and 1 deletions

View File

@ -12,7 +12,9 @@ export class APIError extends Error {
}
export function getFunctionUrl(name: string) {
if (process.env.NEXT_PUBLIC_FIREBASE_EMULATE) {
if (process.env.NEXT_PUBLIC_FUNCTIONS_URL) {
return `${process.env.NEXT_PUBLIC_FUNCTIONS_URL}/${name}`
} else if (process.env.NEXT_PUBLIC_FIREBASE_EMULATE) {
const { projectId, region } = ENV_CONFIG.firebaseConfig
return `http://localhost:5001/${projectId}/${region}/${name}`
} else {

26
dev.sh Executable file
View File

@ -0,0 +1,26 @@
#!/bin/bash
ENV=${1:-dev}
case $ENV in
dev)
FIREBASE_PROJECT=dev
NEXT_ENV=DEV ;;
prod)
FIREBASE_PROJECT=prod
NEXT_ENV=PROD ;;
*)
echo "Invalid environment; must be dev or prod."
exit 1
esac
firebase use $FIREBASE_PROJECT
# run all of: local functions, next.js dev server, typechecking on web project
npx concurrently \
-n FUNCTIONS,NEXT,TS \
-c white,magenta,cyan \
"yarn --cwd=functions dev" \
"cross-env NEXT_PUBLIC_FUNCTIONS_URL=http://localhost:8080 \
NEXT_PUBLIC_FIREBASE_ENV=${NEXT_ENV} \
yarn --cwd=web serve" \
"cross-env yarn --cwd=web ts-watch"

View File

@ -12,6 +12,7 @@
"start": "yarn shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log",
"dev": "nodemon src/serve.ts",
"serve": "firebase use dev && yarn build && firebase emulators:start --only functions,firestore --import=./firestore_export",
"db:update-local-from-remote": "yarn db:backup-remote && gsutil rsync -r gs://$npm_package_config_firestore/firestore_export ./firestore_export",
"db:backup-local": "firebase emulators:export --force ./firestore_export",

View File

@ -9,6 +9,7 @@
"devdev": "cross-env NEXT_PUBLIC_FIREBASE_ENV=DEV yarn dev",
"dev:dev": "yarn devdev",
"dev:the": "cross-env NEXT_PUBLIC_FIREBASE_ENV=THEOREMONE yarn dev",
"dev:local": "cross-env NEXT_PUBLIC_FUNCTIONS_URL=http://localhost:8080 yarn devdev",
"dev:emulate": "cross-env NEXT_PUBLIC_FIRESTORE_EMULATE=TRUE yarn devdev",
"build": "next build",
"start": "next start",