Giter Club home page Giter Club logo

Comments (5)

h2non avatar h2non commented on June 21, 2024

Can you show some code?

from rocky.

MrSpark2591 avatar MrSpark2591 commented on June 21, 2024
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.

tomas-fp avatar tomas-fp commented on June 21, 2024

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.

MrSpark2591 avatar MrSpark2591 commented on June 21, 2024

yeh tried, that is not working :(
for other APIs it's working well but when it comes to file upload it fails.

from rocky.

MrSpark2591 avatar MrSpark2591 commented on June 21, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.