📡 ExpressJS Middleware

Using middleware to apply logic to multiple endpoints

file_type_typescript http.ts
// Custom Middleware
const auth = (request, response, next) => {
  if (!request.headers.authorization) {
    response.status(400).send('unauthorized');
  }
  next();
};

// Multi Route ExpressJS HTTP Function
const app = express();
app.use(cors({ origin: true }));
app.use(auth);

Questions? Let's chat

Open Discord