Questions tagged [middleware]

Middleware is computer software that provides services to software applications beyond those available from the operating system. It can be described as "software glue".

Middleware is a software component (or components) that sits "in the middle" between applications and the operating system. Typically, middleware will facilitate application development by providing services such as communications, file access, or thread locking that have a common Application Programming Interface (API) across multiple operating systems.

Communications Middleware is a specific kind of middleware that allows for interprocess communications (on one machine or across a network). The purpose of Communications Middleware is to simplify the designing, programming, and managing of software applications by streamlining the way these applications receive and process data. Communications Middleware simplifies writing communications software while providing sophisticated built-in features, reducing development costs.

Examples of communications middleware include:

4333 questions
11
votes
4 answers

Get response status code in a middleware

I am building an app in which I am trying to build my own logging system for each request. For each request, I'd like to log the timestamp, the method used, the route, and finally the response code that has been sent to the client. I have the…
nook
  • 1,729
  • 1
  • 12
  • 34
11
votes
2 answers

Asp.Net Core 2.x middleware syntax

I encountered several ways of writing simple middleware directly in Startup.Configure() method: // Syntax 1. app.Use((context, next) => { context.Response.Headers.Add("X-Content-Type-Options", "nosniff"); return next(); }); // Syntax…
synergetic
  • 7,756
  • 8
  • 65
  • 106
11
votes
2 answers

C# DotNet Core Middleware Wrap Response

I have a simple controller action which looks like: public Task> GetData() { IEnumerable data = new List(); return data; } I want to be able to inspect the return value from within the…
Lemex
  • 3,772
  • 14
  • 53
  • 87
11
votes
3 answers

Add custom middleware to Laravel Passport endpoints

I have a standard Laravel Passport setup on 5.4 - it all works fine and is generating tokens. I protect my API routes using the auth:api middleware as well as a custom middleware that checks that specific headers in a request are present and valid…
fatuous.logic
  • 750
  • 1
  • 5
  • 16
11
votes
2 answers

What is the difference between a reducer and middleware?

I'm having a little trouble understanding the difference of application between a reducer and middleware. A number of sites describe middleware even giving precise definitions: It provides a third-party extension point between dispatching an…
Druckles
  • 3,161
  • 2
  • 41
  • 65
11
votes
2 answers

How to test response data from Express in Jest

I'm writing unit tests for separate middleware functions in Node/Express using Jest. A simple example of the middleware: function sendSomeStuff(req, res, next) { try { const data = {'some-prop':'some-value'}; res.json(data); …
lennyklb
  • 1,307
  • 2
  • 15
  • 32
11
votes
1 answer

How to add a middleware only on POST with Express and Node

I have a middleware that I want to be applied only when the http method is post. The following works fine, but I get the feeling there is a better way: 'use strict' const express = require('express'), router =…
twharmon
  • 4,153
  • 5
  • 22
  • 48
11
votes
5 answers

Catch exception from controller in middleware

I have a laravel controller that can throw an exception, and a global middleware that catches that exception. In semi pseudo code: // App\Controllers\... class Controller { function store() { throw new FormException; // via validation etc, but…
Rudie
  • 52,220
  • 42
  • 131
  • 173
11
votes
1 answer

After sending response, how to end the current request processing in Node/Express?

There are a few posts on this question but none that answers the issue directly, head-on. Let me clarify that I understand (or so I think) the use of next(), next('route'), return next(), return and their impact on control flow. My entire…
Sunny
  • 9,245
  • 10
  • 49
  • 79
11
votes
4 answers

Using Laravel Auth middleware

Laravel 5.1 really had minimal documentation.. I need clear idea about how to protect routes using Auth middileware.. Documentation tells to add "middleware" => "auth" parameter to route. or can do public function __construct() { …
harish
  • 578
  • 2
  • 8
  • 21
11
votes
1 answer

Laravel 5 redirect loop error

I trying to make a login and admin script, the problem is that I have a redirect loop I dont know why. I want the login users and can be in the / path not /home. If change return new RedirectResponse(url('/')); to return new…
user4012084
11
votes
4 answers

Is it possible to skip route middleware in node express?

Take the following POST function in express. (I am using express 3.5.1) app.post('/example', someFunctionOne, someFunctionTwo, function(req, res){ if(!req.someVar){ return res.send(400, { message: 'error'}); } else{ return…
Paulie
  • 1,567
  • 4
  • 16
  • 21
11
votes
3 answers

Bottle middleware to catch exceptions of a certain type?

Given this simple Bottle code: def bar(i): if i%2 == 0: return i raise MyError @route('/foo') def foo(): try: return bar() except MyError as e: response.status_code = e.pop('status_code') return…
stackoverflowuser95
  • 1,992
  • 3
  • 20
  • 30
11
votes
2 answers

express/connect middleware which executes after the response is sent to the client

Is it possible to write a middleware which executes after the response is sent to a client or after the request is processed and called just before sending the response to client?
Selvaraj M A
  • 3,096
  • 3
  • 30
  • 46
10
votes
1 answer

How to response with JSON format using Ruby Rack middleware

How to reply a simple ruby rack server with JSON object , lets assume mt server is something like : app = Proc.new do |env| [200, { 'Content-Type' => 'text/plain' }, ['Some body']] end Rack::Handler::Thin.run(app, :Port => 4001, :threaded =>…
Eqbal
  • 1,819
  • 2
  • 16
  • 25