From 00f142ec7ebea22bed94f0ced3c18552dbbd40d9 Mon Sep 17 00:00:00 2001 From: TrueMilli <61841994+TrueMilli@users.noreply.github.com> Date: Fri, 3 Jun 2022 21:17:31 +0200 Subject: [PATCH 1/3] vscode settings (#409) * vscode settings * Working debugger config --- .vscode/launch.json | 37 +++++++++++++++---------------------- .vscode/settings.json | 11 ++++++++++- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index c35acf8d..d832421b 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,23 +1,16 @@ { - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "type": "chrome", - "request": "launch", - "name": "Launch Chrome against localhost", - "url": "http://localhost:3000", - "webRoot": "${workspaceRoot}" - }, - { - "type": "chrome", - "request": "attach", - "name": "Attach to Chrome", - "port": 9222, - "urlFilter": "http://localhost:3000/*", - "webRoot": "${workspaceFolder}" - } - ] -} \ No newline at end of file + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Attach to Chrome", + "type": "chrome", + "request": "attach", + "port": 9222, // chrome needs to be started with the parameter "--remote-debugging-port=9222" + "urlFilter": "http://localhost:3000/*", + "webRoot": "${workspaceFolder}/web" + } + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json index e262c75c..7819cbe0 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,13 @@ { "javascript.preferences.importModuleSpecifier": "shortest", - "typescript.preferences.importModuleSpecifier": "shortest" + "typescript.preferences.importModuleSpecifier": "shortest", + "files.eol": "\r\n", + "search.exclude": { + "**/node_modules": true, + "**/package-lock.json": true, + "**/yarn.lock": true + }, + "editor.formatOnSave": true, + "editor.formatOnPaste": true, + "editor.defaultFormatter": "esbenp.prettier-vscode" } From 7572e07489111e5f7c5d38a379ebee0f49d401b2 Mon Sep 17 00:00:00 2001 From: Marshall Polaris Date: Fri, 3 Jun 2022 14:49:09 -0700 Subject: [PATCH 2/3] Add a /health function for ease of benchmarking (#412) * Slightly more defensive API endpoints * Add health endpoint for benchmarking trivial Firebase fns --- functions/src/api.ts | 8 ++++---- functions/src/health.ts | 11 +++++++++++ functions/src/index.ts | 1 + 3 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 functions/src/health.ts diff --git a/functions/src/api.ts b/functions/src/api.ts index 31f14257..36b63692 100644 --- a/functions/src/api.ts +++ b/functions/src/api.ts @@ -137,11 +137,11 @@ export const validate = (schema: T, val: unknown) => { export const newEndpoint = (methods: [string], fn: Handler) => functions.runWith({ minInstances: 1 }).https.onRequest(async (req, res) => { - await applyCors(req, res, { - origin: [CORS_ORIGIN_MANIFOLD, CORS_ORIGIN_LOCALHOST], - methods: methods, - }) try { + await applyCors(req, res, { + origin: [CORS_ORIGIN_MANIFOLD, CORS_ORIGIN_LOCALHOST], + methods: methods, + }) if (!methods.includes(req.method)) { const allowed = methods.join(', ') throw new APIError(405, `This endpoint supports only ${allowed}.`) diff --git a/functions/src/health.ts b/functions/src/health.ts new file mode 100644 index 00000000..944f8677 --- /dev/null +++ b/functions/src/health.ts @@ -0,0 +1,11 @@ +import { newEndpoint } from './api' + +export const health = newEndpoint(['GET'], async (_req, [user, _]) => { + return { + message: 'Server is working.', + user: { + id: user.id, + username: user.username, + }, + } +}) diff --git a/functions/src/index.ts b/functions/src/index.ts index f18b6109..81ea59e5 100644 --- a/functions/src/index.ts +++ b/functions/src/index.ts @@ -3,6 +3,7 @@ import * as admin from 'firebase-admin' admin.initializeApp() // export * from './keep-awake' +export * from './health' export * from './transact' export * from './place-bet' export * from './resolve-market' From b89753e1fe8208f22f934b64556a7c2f9d42c1d7 Mon Sep 17 00:00:00 2001 From: Forrest Wolf Date: Fri, 3 Jun 2022 17:10:14 -0500 Subject: [PATCH 3/3] Add `yarn verify` script (#378) * Add yarn check script * Rename * Add verify script to subdirectories for convenience --- common/package.json | 4 +++- functions/package.json | 3 ++- package.json | 4 +++- web/package.json | 3 ++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/common/package.json b/common/package.json index 54e0e2fa..1bd67851 100644 --- a/common/package.json +++ b/common/package.json @@ -2,7 +2,9 @@ "name": "common", "version": "1.0.0", "private": true, - "scripts": {}, + "scripts": { + "verify": "(cd .. && yarn verify)" + }, "sideEffects": false, "dependencies": { "lodash": "4.17.21" diff --git a/functions/package.json b/functions/package.json index 49352969..0b012401 100644 --- a/functions/package.json +++ b/functions/package.json @@ -15,7 +15,8 @@ "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", "db:rename-remote-backup-folder": "gsutil mv gs://$npm_package_config_firestore/firestore_export gs://$npm_package_config_firestore/firestore_export_$(date +%d-%m-%Y-%H-%M)", - "db:backup-remote": "yarn db:rename-remote-backup-folder && gcloud firestore export gs://$npm_package_config_firestore/firestore_export/" + "db:backup-remote": "yarn db:rename-remote-backup-folder && gcloud firestore export gs://$npm_package_config_firestore/firestore_export/", + "verify": "(cd .. && yarn verify)" }, "main": "lib/functions/src/index.js", "dependencies": { diff --git a/package.json b/package.json index ecefc755..a5c1e29e 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,9 @@ "functions", "web" ], - "scripts": {}, + "scripts": { + "verify": "(cd web && npx prettier --check .; yarn lint --max-warnings 0; tsc --pretty --project tsconfig.json --noEmit); (cd common && npx eslint . --max-warnings 0); (cd functions && npx eslint . --max-warnings 0; tsc --pretty --project tsconfig.json --noEmit)" + }, "dependencies": {}, "devDependencies": { "@typescript-eslint/eslint-plugin": "5.25.0", diff --git a/web/package.json b/web/package.json index 3e638906..889265c9 100644 --- a/web/package.json +++ b/web/package.json @@ -13,7 +13,8 @@ "start": "next start", "lint": "next lint", "format": "npx prettier --write .", - "postbuild": "next-sitemap" + "postbuild": "next-sitemap", + "verify": "(cd .. && yarn verify)" }, "dependencies": { "@headlessui/react": "1.6.1",