Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ name: Run Tests

on:
pull_request:
branches:
- main

jobs:
test:
if: github.base_ref == 'main'
runs-on: ubuntu-latest

steps:
Expand All @@ -16,7 +15,7 @@ jobs:
- name: Set up Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: "1.2.18" # or pin to whatever Bun version you need
bun-version: "1.2.18"

- name: Cache Bun dependencies
uses: actions/cache@v4
Expand All @@ -36,3 +35,10 @@ jobs:

- name: Run tests
run: bun jest
skip-tests:
if: github.base_ref != 'main'
runs-on: ubuntu-latest

steps:
- name: Skip tests for non-main PR
run: echo "Tests skipped - PR is not targeting main branch"
47 changes: 41 additions & 6 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"@supabase/supabase-js": "^2.50.5",
"@types/cors": "^2.8.19",
"@types/express": "^5.0.3",
"@types/morgan": "^1.9.10",
"@types/multer": "^2.0.0",
"@types/node": "^24.0.13",
"@types/uuid": "^10.0.0",
Expand All @@ -62,10 +63,12 @@
"express": "^5.1.0",
"husky": "^9.1.7",
"jest": "^30.0.4",
"morgan": "^1.10.1",
"multer": "^2.0.1",
"ts-jest": "^29.4.0",
"ts-node": "^10.9.2",
"uuid": "^11.1.0"
"uuid": "^11.1.0",
"winston": "^3.19.0"
},
"private": true
}
11 changes: 8 additions & 3 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@ import { errorHandler } from "./utils/apiError";
import { createClient } from "@supabase/supabase-js";
import config from "./config";
import path from "path";

import { logger } from "./utils/logger";
import morgan from "morgan";
// Initialize Supabase client for storage operations
export const supabase = createClient(
config.SUPABASE_URL,
config.SUPABASE_SERVICE_ROLE_KEY,
);

const app = express();


class LoggerStream {
write(message: string) {
logger.info(message.substring(0, message.lastIndexOf('\n')));
}
}
app.use(morgan('combined', { stream: new LoggerStream()}));
app.use(
cors({
origin: config.ALLOWED_ORIGINS || "*",
Expand Down
4 changes: 2 additions & 2 deletions src/utils/apiError.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Request, Response, NextFunction } from "express";

import { logger } from "./logger";
/**
* A custom error type that carries an HTTP status code.
*/
Expand Down Expand Up @@ -40,7 +40,7 @@ export function errorHandler(
error: true,
message,
};

logger.error('ERROR 🔥', err);
// Include stack trace in development for debugging
if (process.env.NODE_ENV === "development" && err instanceof Error) {
responseBody.stack = err.stack;
Expand Down
25 changes: 25 additions & 0 deletions src/utils/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import winston from 'winston';

const logger = winston.createLogger({
level: "http",
format: winston.format.combine(
winston.format.timestamp(),
winston.format.json()
),
transports: [
new winston.transports.Console({
format: winston.format.combine(
winston.format.colorize(),
winston.format.simple()
)
})
]
});

logger.stream = {
write: (message: any) => {
logger.info(message.trim());
}
} as any;

export { logger };