eletrotupi / tcc/ commit / 80ca9e5

api: clean up prisma client injection awkwardness

Pedro Lucas Porcellis porcellis@eletrotupi.com · 6 months ago 80ca9e5b0f228e9fca6e9f46e052002580d27ee5 Browse files
Parents 6a9fe5b
Changed files
1
Additions
+1
Deletions
-7
api/src/createApp.ts modified+1 -7
api/src/createApp.ts
1 1
import express from 'express';
2 2
import cors from 'cors';
3 3
import bodyParser from 'body-parser';
4 4
import morgan from 'morgan';
5 5
import userRouter from '@app/routes/users';
6 6
import authRouter from '@app/routes/auth';
7 7
import { errorHandler } from '@app/middleware/errorHandler';
8 8
import { PrismaClient } from '@prisma/client';
9 9

10 -
export function createApp(prismaClient?: PrismaClient) {
10 +
export function createApp() {
11 11
  const app = express();
12 12

13 13
  // Configure CORS
14 14
  app.use(cors({
15 15
    origin: process.env.FRONTEND_URL || '*',
16 16
    credentials: true
17 17
  }));
18 18

19 -
  app.use(express.json());
20 19
  app.use(bodyParser.json());
21 20

22 21
  // Only use morgan in non-test environments
23 22
  if (process.env.NODE_ENV !== 'test') {
24 23
    app.use(morgan('combined'));
25 -
  }
26 -

27 -
  // Make prisma client available to routes if provided (for testing)
28 -
  if (prismaClient) {
29 -
    app.locals.prisma = prismaClient;
30 24
  }
31 25

32 26
  app.use("/users", userRouter);
33 27
  app.use("/auth", authRouter);
34 28

35 29
  app.use(errorHandler); // always last
36 30

37 31
  return app;
38 32
}