Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

330
Vistas
How does a method work as callback in app.use()?

Normally, a function is passed as callback in app.use(), like so:

const express = require('express');
const app = express();

app.use(function (req, res, next) {
  console.log('Time:', Date.now());
  next();
});

In the case of node-expose-sspi however a method is passed:

const express = require('express');
const { sso } = require('node-expose-sspi');

const app = express();
app.use(sso.auth()); //stores something in req.sso

app.use((req, res, next) => {
  res.json({
    sso: req.sso,
  });
});

Why is the method passed with ()? If it uses () why is it no called immediately (without arguments)?
Also, how can I wrap a method in a callback function, e.g.

app.use(myCallback);

function myCallback(req, res, next) {
  sso.auth(); //req.sso is undefined
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

app.use(sso.auth());

calls sso.auth() and app.use()s its return value.

You can find over here in the node-expose-sspi source that .auth() indeed returns a new middleware function.

As for the second question

Also, how can I wrap a method in a callback function

you shouldn't do that – Express will call your used middlewares in order; a subsequent callback will have access to whatever a previous middleware has injected into the request.

If you for some reason really need to do that,

const ssoAuth = sso.auth();

function myCallback(req, res, next) {
  ssoAuth(req, res, () => {
    // whatever would regularly be in `myCallback`
    next();
  });
}
``
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda