Comments (5)
Can you show some code?
from rocky.
proxy
.useForward(function(req, res, next) {
var cookies = cookie.parse(req.headers.cookie);
if (cookies.token) {
var session = JSON.parse(redis.getSession(cookies.token)); // this line is redis call which is async task and will take some time
if (session) {
req.headers['authorization'] = session.token.accessToken;
req.headers['auth-provider'] = session.token.authProvider;
}
next();
} else {
next();
}
}
})
from rocky.
What about something like, assuming it's a callback-based async code:
proxy.useForward(function(req, res, next) {
var cookies = cookie.parse(req.headers.cookie);
if (cookies.token) {
redis.getSession(cookies.token, (err, token) => {
if (err) {
// do something with the error
return next(err)
}
var session = JSON.parse(token)
if (session) {
req.headers['authorization'] = session.token.accessToken;
req.headers['auth-provider'] = session.token.authProvider;
}
next()
})
} else {
next();
}
}
})
from rocky.
yeh tried, that is not working :(
for other APIs it's working well but when it comes to file upload it fails.
from rocky.
in Nginx it is giving me : prematurely closed connection while reading response header from upstream client
My nginx config
`server {
listen 80;
server_name peoplehum.dev www.peoplehum.dev;
#rewrite ^/(.*)/$ /$1 permanent;
charset utf-8;
keepalive_requests 100;
keepalive_timeout 100s;
gzip on;
gzip_http_version 1.1;
gzip_vary on;
gzip_comp_level 6;
gzip_proxied any;
gzip_buffers 16 8k;
gzip_disable "MSIE [1-6].(?!.*SV1)";
client_max_body_size 16M;
#include /etc/nginx/proxy_header.conf;
#include /etc/nginx/proxy_buffer.conf;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
proxy_set_header HOST $host;
#X-Forwarded-Proto header gives the proxied server information about the schema of the original client request (whether it was an http or an https request).
proxy_set_header X-Forwarded-Proto $scheme;
#The X-Real-IP is set to the IP address of the client so that the proxy can correctly make decisions or log based on this information.
proxy_set_header X-Real-IP $remote_addr;
#The X-Forwarded-For header is a list containing the IP addresses of every server the client has been proxied through up to this point.
#In the example above, we set this to the $proxy_add_x_forwarded_for variable.
#This variable takes the value of the original X-Forwarded-For header retrieved from the client and adds the Nginx server's IP address to the end.
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}`
from rocky.
Related Issues (20)
- Bug in Middleware Flow (only for HEAD Requests?) HOT 2
- Support for Additional HTTP Methods HOT 1
- Using 'body-parser' middleware causes TypeError HOT 3
- How to update load balance ? HOT 3
- can we have one more option for method ? HOT 2
- how to achieve app level load balancing? HOT 8
- Changing request URL randomly fails to get any response
- Can we have middleware to support custom load-balancing? HOT 3
- websocket middleware usage and examples needed, eg sniffing HOT 2
- custom load balancer support HOT 5
- How to access upstream response's statusCode in response middleware callbacks? HOT 2
- Test http2 support
- Request cloning breaks HTTP agents
- transformRequest has a gotcha, docs or code fix?
- Rocky breaks if domains has no registered A DNS records HOT 3
- Release security patch to npm HOT 1
- Rocky not working on node@16 HOT 2
- Forwarding with Express integration not working HOT 4
- Remove built-in retry support
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rocky.