Skip to content

Commit 8660a3b

Browse files
authored
Merge pull request #18 from oslabs-beta/jaime/code-review-and-suggestions
[review] jaime's input / insights
2 parents 2706280 + 4dae787 commit 8660a3b

File tree

8 files changed

+77
-22
lines changed

8 files changed

+77
-22
lines changed

server/db.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
// definitely periodically run Prettier or some other formatter on your codebase!
2+
13
import 'dotenv/config';
24
import pkg from 'pg';
35
const { Pool } = pkg;
46

5-
6-
console.log("🔐 DB SSL rejectUnauthorized:", process.env.DB_SSL_REJECT_UNAUTHORIZED);
7+
console.log(
8+
'🔐 DB SSL rejectUnauthorized:',
9+
process.env.DB_SSL_REJECT_UNAUTHORIZED
10+
);
711
export const pool = new Pool({
812
connectionString: process.env.DATABASE_URL,
913
max: parseInt(process.env.DB_POOL_MAX || '8', 10),
@@ -17,7 +21,9 @@ export const pool = new Pool({
1721
},
1822
});
1923

20-
pool.on('error', (err) => console.error('[DB] Unexpected error on idle client', err));
24+
pool.on('error', (err) =>
25+
console.error('[DB] Unexpected error on idle client', err)
26+
);
2127

2228
export async function query(sql, params = []) {
2329
const start = Date.now();

server/lib/github-oauth.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// this file is great, and organized.
2+
13
export function buildAuthorizeUrl({ clientId, redirectUri, scopes, state }) {
24
const params = new URLSearchParams({
35
client_id: clientId,

server/routes/agent.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/* just commenting on this file to say:
2+
in your /routes folder, make sure to keep your router names consistent!
3+
*/
4+
15
import express from 'express';
26
import { runWizardAgent } from '../agent/wizardAgent.js';
37
import { pipeline_generator } from '../tools/pipeline_generator.js';

server/routes/auth.aws.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,17 @@ import {
1313
} from "@aws-sdk/client-sso-oidc";
1414

1515
const router = Router();
16+
17+
// i'd set up some linting to ensure that you're catching unused variables, like the one below
18+
// this will be important in terms of keeping your codebase organized & professional down the line
1619
const SESSION_SECRET = process.env.SESSION_SECRET;
1720

1821
// ✅ Start AWS connect flow
1922
router.post("/connect", requireSession, async (req, res) => {
2023
const { sso_start_url, sso_region, account_id, role_to_assume } = req.body;
21-
const userId = req.user.id;
24+
25+
// if you want to get fancy with destructuring, i'd do this personally:
26+
const { user: { id: userId } } = req;
2227

2328
// Validate required parameters
2429
if (!sso_start_url || typeof sso_start_url !== 'string' || sso_start_url.trim() === '') {

server/routes/auth.github.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ router.get('/start', (req, res) => {
4141
return res.redirect(url);
4242
});
4343

44+
// remove commented-out code like this if you're not gonna use it
45+
4446
// router.get('/callback', async (req, res) => {
4547
// try {
4648
// const { code, state } = req.query;

server/routes/pipelineCommit.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { upsertWorkflowFile } from '../tools/github_adapter.js';
55

66
const router = Router();
77

8+
// this is nice. consider using JSDoc at some point in the future to document your routes/functions/etc.
9+
// it really elevates a codebase's professionalism
810
/**
911
* POST /mcp/v1/pipeline_commit
1012
* Body:

server/server.js

Lines changed: 51 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
/*
2+
i'd recommend organizing your imports at the top of files (here and in other files),
3+
perhaps by sections separated with spaces, i.e.:
4+
5+
// library dependencies
6+
import express from 'express'
7+
import cors from 'cors'
8+
import helmet from 'helmet'
9+
import { z } from 'zod'
10+
...
11+
12+
// routes
13+
import mcpRoutes from './routes/mcp.js'
14+
import agentRoutes from './routes/agent.js'
15+
...
16+
17+
// helper functions / constants / other data / etc.
18+
import { healthCheck } from './db.js'
19+
import { query } from './db.js'
20+
...
21+
22+
all up to you how you want to do this. but i find it helps with readability and organization.
23+
*/
24+
125
import 'dotenv/config';
226
import express from 'express';
327
import cors from 'cors';
@@ -27,13 +51,17 @@ app.use(morgan('dev'));
2751
app.use(cookieParser());
2852

2953
// --- Request Logging Middleware ---
30-
app.use((req, res, next) => {
54+
55+
// a convention you can choose to follow is prefixing unused parameters with an underscore
56+
app.use((req, _res, next) => {
3157
const user = req.headers['x-user-id'] || 'anonymous';
3258
console.log(
3359
`[${new Date().toISOString()}] ${req.method} ${
3460
req.originalUrl
3561
} | user=${user}`
3662
);
63+
// ^ nice logging; this is great.
64+
3765
next();
3866
});
3967

@@ -50,17 +78,21 @@ app.get('/db/ping', async (_req, res) => {
5078
}
5179
});
5280

81+
// Mount users route at /users
82+
// ^ imo, this kind of comment is a bit useless: it's obvious to other devs what it does :)
83+
app.use('/', userRouter);
84+
85+
// i'd probably put the other routes here as well.
86+
5387
/** Users */
5488
const UserBody = z.object({
5589
email: z.string().email(),
5690
github_username: z.string().min(1).optional(),
5791
});
58-
// Mount users route at /users
59-
app.use('/', userRouter);
6092

6193
// Create or upsert user by email
6294
app.post('/users', async (req, res) => {
63-
const parse = UserBody.safeParse(req.body);
95+
const parse = UserBody.safeParse(req.body); // love that you are doing this. great.
6496
if (!parse.success)
6597
return res.status(400).json({ error: parse.error.message });
6698
const { email, github_username } = parse.data;
@@ -82,6 +114,9 @@ app.post('/users', async (req, res) => {
82114
}
83115
});
84116

117+
// you definitely want to minimize commented-out code like below
118+
// if you don't need it, just remove it.
119+
85120
// app.get('/users', async (_req, res) => {
86121
// try {
87122
// const rows = await query(
@@ -125,30 +160,28 @@ app.get('/connections', async (_req, res) => {
125160
}
126161
});
127162

128-
// // --- Request Logging Middleware ---
129-
// app.use((req, res, next) => {
130-
// const user = req.headers['x-user-id'] || 'anonymous';
131-
// console.log(
132-
// `[${new Date().toISOString()}] ${req.method} ${
133-
// req.originalUrl
134-
// } | user=${user}`
135-
// );
136-
// next();
137-
// });
138-
139163
// -- Agent entry point
164+
165+
/*
166+
you should keep your router names consistent:
167+
- deploymentsRouter
168+
- agentRouter (not agentRoutes)
169+
- authAwsRouter (not authAws)
170+
- authGoogleRouter (not authGoogle)
171+
etc.
172+
*/
173+
174+
// also, i'd probably move these routes closer to the top of the file, so they're easier to find.
175+
140176
app.use('/deployments', deploymentsRouter);
141177
app.use('/agent', agentRoutes);
142178
app.use('/mcp/v1', pipelineCommitRouter);
143179
app.use('/mcp/v1', mcpRoutes);
144180

145-
// Mount GitHub OAuth routes at /auth/github
146181
app.use('/auth/github', githubAuthRouter);
147182
app.use(authRoutes);
148-
// Mount AWS SSO routes
149183
app.use('/auth/aws', authAws);
150184

151-
// Mount Google OAuth routes
152185
app.use('/auth/google', authGoogle);
153186

154187
app.use('/jenkins', jenkinsRouter);

server/src/config/env.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import dotenv from "dotenv";
22
dotenv.config();
33

4+
// definitely be sure to remove these kinds of logs in production!
45
console.log("🧾 MCP_API_KEY from .env:", process.env.MCP_API_KEY);
56

67
export const config = {

0 commit comments

Comments
 (0)