why not make middleware or hooks that works exactly before sending response that could change or alter the response object

Abierto
#3,945 5 comentarios 2 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
25/100
Tipo de issue
Nueva funcionalidad
Claridad
Necesita aclaración
Estado de actividad
Estancado
Stack tecnológico
express, javascript, node.js
Área
api, backend

Línea de trabajo

El issue no menciona archivos, pruebas ni puntos de entrada. Comienza determinando dónde Express gestiona el envío de respuestas y cómo se ordena el middleware; después, establece si un pre-send hook compatible puede modificar de forma segura los headers o los bodies, y define pruebas para el comportamiento previsto.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

ideas

Problem statement

There is a problem which always happens what if we wanted to make certain actions or wrap our responses all our responses in express in a certain standard way right now there is no built in hooks or middlewares which works before the sending

Lots of inefficient workarounds

I know there is workarounds by just overriding the response object but thats sometimes not efficient enough and sometimes breaks some functions while responding so , why not make hooks for the main response functions and just pass in the req and res objects for the user to modify and just return the res and req after the modification.

Just a proposed way for the way to make such hooks

let express = require('express');
let app = express();
let bodyParser = require('body-parser');

// some middlewares

app.use(bodyParser());

// routes here
app.get('/test',(req,res) => res.send('I am a test function'));

// now put a hook in the app to run before the send
// this is an example of how to make send hook 
app.hooks.onSend = (req,res) => {

    res.body = {
            body: res.body,
            status : 200
   };

   return { res, req };
};

benefits

It is a simple use case but it will help alot of people make their code way better.
by at least making a way to change res object either in headers or in the body or any other thing according to what they need to change.

Lenguaje dominante
JavaScript
Estrellas
69.7k
Forks
25.6k
Merge medio
2 d 9 h
PR fusionados (30 d)
4

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de expressjs/express

Todos los issues de expressjs/express

Issues similares

Más issues de JavaScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.