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
50
votes
9 answers

Auth::user() returns null

I use Laravel 5.2 and have a problem with middleware. There is the code in the routes.php use Illuminate\Contracts\Auth\Access\Gate; Route::group(['middleware' => 'web'], function () { Route::auth(); Route::get('/',…
imladris
  • 565
  • 2
  • 5
  • 9
49
votes
11 answers

Exclude route from express middleware

I have a node app sitting like a firewall/dispatcher in front of other micro services and it uses a middleware chain like below: ... app.use app_lookup app.use timestamp_validator app.use request_body app.use checksum_validator app.use…
kreek
  • 8,774
  • 8
  • 44
  • 69
48
votes
6 answers

Express 4 middleware error handler not being called

For certain pages I have custom 500, 404 and 403 error handling in my app. So for instance after an unsuccessful database query I'd go: return next({status: 404, message: 'Record not found'}); or return next(new Error('Bad things have…
ChrisRich
  • 8,300
  • 11
  • 48
  • 67
44
votes
7 answers

Where do you put your Rack middleware files and requires?

I'm in the process of refactoring some logic built into a Rails application into middleware, and one annoyance I've run into is a seeming lack of convention for where to put them. Currently I've settled on app/middleware but I could just as easily…
Adam Lassek
  • 35,156
  • 14
  • 91
  • 107
43
votes
2 answers

Why middleware in ASP.NET Core requires specific semantics, but not an interface?

As known, IApplicationBuilder of the method Configure (class Startup) in ASP.NET Core requires specific semantics (to have method 'Invoke' with input parameter of HttpContext type and Task as return value). But why it's not implemented as interface?…
Oleg Sh
  • 8,496
  • 17
  • 89
  • 159
42
votes
3 answers

How to use the middleware to check the authorization before entering each route in express?

I want to check the authorization of the users of my web app when they entered the url. But when I used an individually middleware to check the authorization, it's useless for the already existing routes, such as: function authChecker(req, res,…
Noah Blues
  • 1,339
  • 2
  • 11
  • 19
42
votes
6 answers

Compojure routes with different middleware

I'm currently writing an API in Clojure using Compojure (and Ring and associated middleware). I'm trying to apply different authentication code depending on the route. Consider the following code: (defroutes public-routes (GET "/public-endpoint"…
user1391110
41
votes
1 answer

How throw forbidden exception from middleware in laravel5?

I am writing a middleware in laravel 5. I want to throw a forbidden exception with code 403 from middleware. My middleware function is given below: use Exception; public function handle($request, Closure $next) { if (!Auth::check()) { …
gsk
  • 2,329
  • 8
  • 32
  • 56
41
votes
3 answers

Access "app" variable inside of ExpressJS/ConnectJS middleware?

This may not me be the right approach, but I want to conditionally add an object/parameter to the app variable inside of an expressJS/connectjS middleware call. Since this function is a callback, what's the standard/best way to access app from…
qodeninja
  • 10,946
  • 30
  • 98
  • 152
41
votes
9 answers

Why don't my Django unittests know that MessageMiddleware is installed?

I'm working on a Django project and am writing unittests for it. However, in a test, when I try and log a user in, I get this error: MessageFailure: You cannot add messages without installing…
Phil Gyford
  • 13,432
  • 14
  • 81
  • 143
40
votes
5 answers

Read Controller and Action name in middleware .Net Core

I am writing a middleware class within my project in order to log the request data into our database. I do not see any easy way to get the controller name and action ? Any chance to do this easily in core? I have something like this: public class…
Metalex
  • 471
  • 1
  • 5
  • 10
38
votes
2 answers

How do I access the Rack environment from within Rails?

I have a Rack application that looks like this: class Foo def initialize(app) @app = app end def call(env) env["hello"] = "world" @app.call(env) end end After hooking my Rack application into Rails, how do I get access to…
Michael Gundlach
  • 106,555
  • 11
  • 37
  • 41
38
votes
9 answers

Cant load a react app after starting server

(node:13176) [DEP_WEBPACK_DEV_SERVER_ON_AFTER_SETUP_MIDDLEWARE] DeprecationWarning: 'onAfterSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option. (Use node --trace-deprecation ... to show where the warning was…
Sagar Nilgar
  • 389
  • 1
  • 3
  • 4
38
votes
3 answers

Laravel: Difference Between Route Middleware and Policy

Developing an app with laravel I realised that what can be done with Policy can exactly be done with Middleware. Say I want to prevent a user from updating a route if he/she is not the owner of the information, I can easily check from the route and…
George
  • 3,757
  • 9
  • 51
  • 86
36
votes
3 answers

React-Redux and Websockets with socket.io

I'm new with that technology React-Redux and I would like your help with some implementation. I want to implement one chat application with sockets (socket.io). First, the user has to sign up (I use passport in the server side) and after, if the…
DustInTheSilence
  • 575
  • 1
  • 7
  • 15