348 questions
244
votes
15
answers
380k
views
How can I enable CORS on Django REST Framework
How can I enable CORS on my Django REST Framework?
the reference doesn't help much, it says that I can do by a middleware, but how can I do that?
305
votes
4
answers
86k
views
Node.js / Express.js - How does app.router work?
Before I ask about app.router I think I should explain at least what I think happens when working with middleware. To use middleware, the function to use is app.use(). When the middleware is being ...
332
votes
10
answers
264k
views
Passing variables to the next middleware using next() in Express.js
I want to pass some variable from the first middleware to another middleware, and I tried doing this, but there was "req.somevariable is a given as 'undefined'".
//app.js
..
app.get('/...
657
votes
9
answers
156k
views
What is Node.js' Connect, Express and "middleware"?
Despite knowing JavaScript quite well, I'm confused what exactly these three projects in Node.js ecosystem do. Is it something like Rails' Rack? Can someone please explain?
53
votes
9
answers
89k
views
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 () {
...
11
votes
1
answer
11k
views
How to force all exceptions to go through a FastAPI middleware?
I am writing an app using FastAPI. Parts of my code raise different exceptions, which I need to process. I want all that processing to be done in a single place (with different except blocks depending ...
109
votes
3
answers
132k
views
Chaining multiple pieces of middleware for specific route in ExpressJS
I want to just verify something but have't been able to find anything in the Express docs or online regarding this (although I know it's a feature).
I could just test this out but I don't really have ...
42
votes
2
answers
67k
views
How to write a custom FastAPI middleware class
I have read FastAPI's documentation about middlewares (specifically, the middleware tutorial, the CORS middleware section and the advanced middleware guide), but couldn't find a concrete example of ...
18
votes
3
answers
13k
views
Django: How can I check the last activity time of user if user didn't log out?
django's User model has a last_login field, which is great if all the users were to log out each time they leave the site, but what if they don't?
How can I track when a user who never logged out and ...
246
votes
15
answers
176k
views
What is middleware exactly? [closed]
I have heard a lot of people talking recently about middleware, but what is the exact definition of middleware? When I look into middleware, I find a lot of information and some definitions, but while ...
36
votes
3
answers
34k
views
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 ...
24
votes
6
answers
61k
views
Parsing Post Form Data Node.js Express
I am getting form data in this form
'------WebKitFormBoundarysw7YYuBGKjAewMhe\r\nContent-Disposition: form-data; name': '"a"\r\n\r\nb\r\n------WebKitFormBoundarysw7YYuBGKjAewMhe--\r\n
I'm trying to ...
39
votes
2
answers
30k
views
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 ...
19
votes
4
answers
37k
views
FASTAPI custom middleware getting body of request inside [duplicate]
Been trying to get the BODY of a request using FASTAPI middleware but it seems i can only get request.headers but not the body. I am in need of the body in order to get a key that I will use to check ...
8
votes
1
answer
5k
views
Django: How to access URL regex parameters inside a middleware class?
I am working on a Django project on Google App Engine. I have a URL like:
http://localhost:8080/[company]/projects/project
Note that [company] is a URL parameter defined in my urls.py like:
(r'(^[a-...
6
votes
4
answers
11k
views
Cakephp 3.5.6 disable CSRF Middleware for controller
I'm trying to disable the CSRF check for a single controller (API), but I'm unable to find how I'm able to achieve this.
The pre 3.5.0 CSRF Component had the ability to be disabled on certain request ...
58
votes
7
answers
43k
views
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
...
46
votes
12
answers
95k
views
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-...
44
votes
9
answers
9k
views
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 django....
19
votes
5
answers
25k
views
How to read request body multiple times in asp net core 2.2 middleware?
I tried this:
Read request body twice
and this:
https://github.com/aspnet/Mvc/issues/4962
but did not work.
I read request body like this:
app.Use(async (context, next) =>
{
var requestBody = ...
15
votes
4
answers
14k
views
How can I combine Go middleware pattern with error returning request handlers?
I am familiar with the Go middleware pattern like this:
// Pattern for writing HTTP middleware.
func middlewareHandler(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http....
13
votes
2
answers
7k
views
Mongoose - how to tap schema middleware into the 'init' event?
It is suggested in the Mongoose docs that I should be able to control the flow using middleware that plugs in to the "init" hook.
However, I have so far had success only with "save" and "validate".
...
5
votes
2
answers
5k
views
Control HTTP headers from outer Go middleware
Let's say I have a middleware in Go where I want to override any existing Server headers with my own value.
// Server attaches a Server header to the response.
func Server(h http.Handler, serverName ...
4
votes
3
answers
9k
views
how to disable middleware in specific page, nuxt middleware
i have declare a middleware that check role of every routes in nuxt.config.js. but want to disable in some pages.
// in nuxt.config.js =>
router: {
middleware: ['role']
...
3
votes
1
answer
17k
views
How to make Selenium scripts work faster?
I use Python Selenium and Scrapy for crawling a website.
But my script is so slow,
Crawled 1 pages (at 1 pages/min)
I use CSS SELECTOR instead of XPATH for optimise the time.
I change the middlewares
...