From a9e23bb7e46b906cf15981192ba9182a22074f51 Mon Sep 17 00:00:00 2001 From: Andrew Bierman <94939237+andrew-bierman@users.noreply.github.com> Date: Mon, 15 Jul 2024 23:08:20 -0400 Subject: [PATCH 1/5] =?UTF-8?q?=F0=9F=93=9D=20update=20example?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/wrangler.toml.example | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/wrangler.toml.example b/server/wrangler.toml.example index 90f5ed2e8..9b73ab290 100644 --- a/server/wrangler.toml.example +++ b/server/wrangler.toml.example @@ -1,8 +1,8 @@ -name = "packrat_api" +name = "packrat-api" main = "src/index.ts" compatibility_date = "2024-03-14" compatibility_flags = ["nodejs_compat"] -# node_compat = true # Sometimes this is needed for tests +# node_compat = true # Sometimes this is needed for tests [[ d1_databases ]] binding = "DB" From 54b83f7a91a8cf57ec663f69b7887cd31c1c30d7 Mon Sep 17 00:00:00 2001 From: Andrew Bierman <94939237+andrew-bierman@users.noreply.github.com> Date: Mon, 15 Jul 2024 23:11:51 -0400 Subject: [PATCH 2/5] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20update=20start=20scrip?= =?UTF-8?q?t?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + packages/cli/src/start.js | 53 ++++++++++++++++++--------------------- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/package.json b/package.json index ef1785a85..56338be5d 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "copy:env:packages": "cp .env packages/.env", "copy:env:server": "cp .env server/.env", "dev:expo": "cd apps/expo && yarn start", + "dev:vite": "cd apps/vite && yarn dev", "dev:next": "cd apps/next && yarn dev", "dev:server": "cd server && yarn start", "expo:export": "cd apps/expo && cp app.example.json app.json && npx expo export --platform web", diff --git a/packages/cli/src/start.js b/packages/cli/src/start.js index d8f1fde16..bfd6950b0 100644 --- a/packages/cli/src/start.js +++ b/packages/cli/src/start.js @@ -1,44 +1,41 @@ const { Select } = require('enquirer'); const { spawn } = require('child_process'); -function runApp(command, args) { +const runApp = (command, args) => { const process = spawn(command, args, { stdio: 'inherit' }); - process.on('error', (error) => { - console.error(`Error: ${error.message}`); - }); - - process.on('close', (code) => { - console.log(`Process exited with code ${code}`); - }); -} + process.on('error', (error) => console.error(`Error: ${error.message}`)); + process.on('close', (code) => + console.log(`Process exited with code ${code}`), + ); +}; -async function startApp() { +const startApp = async () => { const prompt = new Select({ name: 'app', message: 'Choose an app to start', - choices: ['Expo', 'Next', 'Server'], + choices: ['Expo', 'Vite', 'Next', 'Server'], }); - const app = await prompt.run(); + try { + const app = await prompt.run(); + + const commands = { + Expo: ['yarn', ['dev:expo']], + Vite: ['yarn', ['dev:vite']], + Next: ['yarn', ['dev:next']], + Server: ['yarn', ['dev:server']], + }; - switch (app) { - case 'Expo': - console.log('Starting Expo...'); - runApp('yarn', ['dev:expo']); - break; - case 'Next': - console.log('Starting Next...'); - runApp('yarn', ['dev:next']); - break; - case 'Server': - console.log('Starting Server...'); - runApp('yarn', ['dev:server']); - break; - default: + if (commands[app]) { + console.log(`Starting ${app}...`); + runApp(...commands[app]); + } else { console.log('No app selected'); - break; + } + } catch (error) { + console.error(`Prompt error: ${error.message}`); } -} +}; startApp().catch(console.error); From 62923ee06ded593b4c50b00db224d3ba614dc437 Mon Sep 17 00:00:00 2001 From: Andrew Bierman <94939237+andrew-bierman@users.noreply.github.com> Date: Mon, 15 Jul 2024 23:14:17 -0400 Subject: [PATCH 3/5] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20add=20logger=20and=20h?= =?UTF-8?q?ealth=20routes=20for=20better=20monitoring?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/index.ts | 4 ++-- server/src/routes/healthRoutes.ts | 31 +++++++++++++++++++++++++++++++ server/src/routes/index.ts | 2 ++ 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 server/src/routes/healthRoutes.ts diff --git a/server/src/index.ts b/server/src/index.ts index 8cf313258..927babea4 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -1,4 +1,5 @@ import { Hono } from 'hono'; +import { logger } from 'hono/logger'; import { fetchHandler } from 'trpc-playground/handlers/fetch'; import { appRouter } from './routes/trpcRouter'; import { honoTRPCServer } from './trpc/server'; @@ -48,8 +49,7 @@ app.use('*', async (c, next) => { }); // SETUP LOGGING -// tRPC is already logging requests, but you can add your own middleware -// app.use('*', logger()); +app.use('*', logger()); // SETUP TRPC SERVER app.use(`${TRPC_API_ENDPOINT}/*`, honoTRPCServer({ router: appRouter })); diff --git a/server/src/routes/healthRoutes.ts b/server/src/routes/healthRoutes.ts new file mode 100644 index 000000000..b48bea5d0 --- /dev/null +++ b/server/src/routes/healthRoutes.ts @@ -0,0 +1,31 @@ +import { Hono } from 'hono'; + +const router = new Hono(); + +/** + * @swagger + * tags: + * name: Health + * description: Health routes + */ + +/** + * @swagger + * /health: + * get: + * tags: + * - Health + * summary: Get health status + * responses: + * 200: + * description: Successful response + * content: + * application/json: + * schema: + * type: object + */ +router.get('/', (c) => { + return c.json({ status: 'ok' }); +}); + +export default router; diff --git a/server/src/routes/index.ts b/server/src/routes/index.ts index 4551e237b..a14675011 100644 --- a/server/src/routes/index.ts +++ b/server/src/routes/index.ts @@ -15,6 +15,7 @@ // import favoriteRouters from './favoriteRoutes'; // import userRoutes from './userRoutes'; import mapPreviewRouter from './mapPreviewRouter'; +import healthRoutes from './healthRoutes'; import { type Context, Hono, type Next } from 'hono'; const router = new Hono(); @@ -59,6 +60,7 @@ const router = new Hono(); // router.use('/favorite', favoriteRouters); // router.use('/openai', openAiRoutes); router.route('/mapPreview', mapPreviewRouter); +router.route('/health', healthRoutes); const helloRouter = new Hono(); helloRouter.get('/', (c: Context, next: Next) => { From fbcb747c6a71620ac50036d6ee557f932569dad5 Mon Sep 17 00:00:00 2001 From: Andrew Bierman <94939237+andrew-bierman@users.noreply.github.com> Date: Mon, 15 Jul 2024 23:17:25 -0400 Subject: [PATCH 4/5] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20bun=20server=20start?= =?UTF-8?q?=20command?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/bun-server/package.json | 1 + package.json | 1 + 2 files changed, 2 insertions(+) diff --git a/apps/bun-server/package.json b/apps/bun-server/package.json index df9731154..21707b13d 100644 --- a/apps/bun-server/package.json +++ b/apps/bun-server/package.json @@ -2,6 +2,7 @@ "name": "bun-server", "scripts": { "start": "bun ./dist/index.js", + "start:prod": "bun start", "dev": "bun --watch ./src/index.ts", "build": "tsc" }, diff --git a/package.json b/package.json index 56338be5d..08594f0e3 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,7 @@ "setup": "yarn && yarn setup:expo && yarn setup:server", "start:prod:ts-node": "cd server && yarn start:ts-node", "start:prod": "cd server && yarn start:prod", + "start:prod:bun": "cd apps/bun-server && yarn start:prod", "start": "node packages/cli/src/start.js", "test:all": "yarn test:expo && yarn test:server", "test:expo": "cd apps/expo && yarn test", From d7912f20851205dcadcbf781565e987db59095d0 Mon Sep 17 00:00:00 2001 From: Andrew Bierman <94939237+andrew-bierman@users.noreply.github.com> Date: Mon, 15 Jul 2024 23:59:08 -0400 Subject: [PATCH 5/5] =?UTF-8?q?=F0=9F=90=9B=20don't=20run=20from=20dist?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/bun-server/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/bun-server/package.json b/apps/bun-server/package.json index 21707b13d..c807205fe 100644 --- a/apps/bun-server/package.json +++ b/apps/bun-server/package.json @@ -1,7 +1,7 @@ { "name": "bun-server", "scripts": { - "start": "bun ./dist/index.js", + "start": "bun src/index.ts", "start:prod": "bun start", "dev": "bun --watch ./src/index.ts", "build": "tsc"