Skip to content

Commit

Permalink
Merge pull request #1095 from andrew-bierman/feat/improve-monitoring
Browse files Browse the repository at this point in the history
Feat/improve monitoring
  • Loading branch information
andrew-bierman authored Jul 16, 2024
2 parents bc20b1f + d7912f2 commit 555f005
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 33 deletions.
3 changes: 2 additions & 1 deletion apps/bun-server/package.json
Original file line number Diff line number Diff line change
@@ -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"
},
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
53 changes: 25 additions & 28 deletions packages/cli/src/start.js
Original file line number Diff line number Diff line change
@@ -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);
4 changes: 2 additions & 2 deletions server/src/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 }));
Expand Down
31 changes: 31 additions & 0 deletions server/src/routes/healthRoutes.ts
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 2 additions & 0 deletions server/src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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) => {
Expand Down
4 changes: 2 additions & 2 deletions server/wrangler.toml.example
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit 555f005

Please sign in to comment.