File tree Expand file tree Collapse file tree 6 files changed +89
-15
lines changed
Expand file tree Collapse file tree 6 files changed +89
-15
lines changed Original file line number Diff line number Diff line change @@ -2,11 +2,10 @@ name: Run Tests
22
33on :
44 pull_request :
5- branches :
6- - main
75
86jobs :
97 test :
8+ if : github.base_ref == 'main'
109 runs-on : ubuntu-latest
1110
1211 steps :
1615 - name : Set up Bun
1716 uses : oven-sh/setup-bun@v2
1817 with :
19- bun-version : " 1.2.18" # or pin to whatever Bun version you need
18+ bun-version : " 1.2.18"
2019
2120 - name : Cache Bun dependencies
2221 uses : actions/cache@v4
3635
3736 - name : Run tests
3837 run : bun jest
38+ skip-tests :
39+ if : github.base_ref != 'main'
40+ runs-on : ubuntu-latest
41+
42+ steps :
43+ - name : Skip tests for non-main PR
44+ run : echo "Tests skipped - PR is not targeting main branch"
Original file line number Diff line number Diff line change 5252 "@supabase/supabase-js" : " ^2.50.5" ,
5353 "@types/cors" : " ^2.8.19" ,
5454 "@types/express" : " ^5.0.3" ,
55+ "@types/morgan" : " ^1.9.10" ,
5556 "@types/multer" : " ^2.0.0" ,
5657 "@types/node" : " ^24.0.13" ,
5758 "@types/uuid" : " ^10.0.0" ,
6263 "express" : " ^5.1.0" ,
6364 "husky" : " ^9.1.7" ,
6465 "jest" : " ^30.0.4" ,
66+ "morgan" : " ^1.10.1" ,
6567 "multer" : " ^2.0.1" ,
6668 "ts-jest" : " ^29.4.0" ,
6769 "ts-node" : " ^10.9.2" ,
68- "uuid" : " ^11.1.0"
70+ "uuid" : " ^11.1.0" ,
71+ "winston" : " ^3.19.0"
6972 },
7073 "private" : true
7174}
Original file line number Diff line number Diff line change @@ -7,16 +7,21 @@ import { errorHandler } from "./utils/apiError";
77import { createClient } from "@supabase/supabase-js" ;
88import config from "./config" ;
99import path from "path" ;
10-
10+ import { logger } from "./utils/logger" ;
11+ import morgan from "morgan" ;
1112// Initialize Supabase client for storage operations
1213export const supabase = createClient (
1314 config . SUPABASE_URL ,
1415 config . SUPABASE_SERVICE_ROLE_KEY ,
1516) ;
1617
1718const app = express ( ) ;
18-
19-
19+ class LoggerStream {
20+ write ( message : string ) {
21+ logger . info ( message . substring ( 0 , message . lastIndexOf ( '\n' ) ) ) ;
22+ }
23+ }
24+ app . use ( morgan ( 'combined' , { stream : new LoggerStream ( ) } ) ) ;
2025app . use (
2126 cors ( {
2227 origin : config . ALLOWED_ORIGINS || "*" ,
Original file line number Diff line number Diff line change 11import { Request , Response , NextFunction } from "express" ;
2-
2+ import { logger } from "./logger" ;
33/**
44 * A custom error type that carries an HTTP status code.
55 */
@@ -40,7 +40,7 @@ export function errorHandler(
4040 error : true ,
4141 message,
4242 } ;
43-
43+ logger . error ( 'ERROR 🔥' , err ) ;
4444 // Include stack trace in development for debugging
4545 if ( process . env . NODE_ENV === "development" && err instanceof Error ) {
4646 responseBody . stack = err . stack ;
Original file line number Diff line number Diff line change 1+ import winston from 'winston' ;
2+
3+ const logger = winston . createLogger ( {
4+ level : "http" ,
5+ format : winston . format . combine (
6+ winston . format . timestamp ( ) ,
7+ winston . format . json ( )
8+ ) ,
9+ transports : [
10+ new winston . transports . Console ( {
11+ format : winston . format . combine (
12+ winston . format . colorize ( ) ,
13+ winston . format . simple ( )
14+ )
15+ } )
16+ ]
17+ } ) ;
18+
19+ logger . stream = {
20+ write : ( message : any ) => {
21+ logger . info ( message . trim ( ) ) ;
22+ }
23+ } as any ;
24+
25+ export { logger } ;
You can’t perform that action at this time.
0 commit comments