diff --git a/apps/bun-server/package.json b/apps/bun-server/package.json index df9731154..c807205fe 100644 --- a/apps/bun-server/package.json +++ b/apps/bun-server/package.json @@ -1,7 +1,8 @@ { "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" }, diff --git a/package.json b/package.json index ef1785a85..08594f0e3 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", @@ -65,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", 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); 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) => { 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"