Skip to content

Instantly share code, notes, and snippets.

View pugazece's full-sized avatar

Pugazh pugazece

  • India
View GitHub Profile
// Approach 1: Express middleware to add headers to all responses
export const addHeaders = (headers = {}) => {
return (req, res, next) => {
// Store original res.json and res.send methods
const originalJson = res.json.bind(res);
const originalSend = res.send.bind(res);
// Override res.json to add headers
res.json = function(data) {
// Add custom headers
@pugazece
pugazece / c
Created August 12, 2025 10:54
server
// server.ts
import express, { Request, Response, NextFunction } from "express";
import type { RequestHandler } from "express";
// ---- Types ----
type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
export interface HandlerDef {
method: HttpMethod;
handler: RequestHandler;
@pugazece
pugazece / credit.ts
Created July 15, 2025 17:08
Reference
import { Router, Request, Response } from 'express';
const router = Router();
// Handler for GET /v1/credit
const getCredit = (req: Request, res: Response) => {
res.json({ message: 'Retrieved credit information' });
};
// Handler for POST /v1/credit