Friday, February 23, 2024
 Popular · Latest · Hot · Upcoming
rated 0 times [  1] [ 1]  / answers: 1 / hits: 18531  / 12 Years ago, tue, april 24, 2012, 12:00:00

I have a simple Express based Node.js web server that I'm using for development of a JavaScript application. I set up the server to use node-http-proxy to proxy API requests the application makes to a Jetty server that is running on a different domain and port. This setup has been working flawlessly until I started to run into problems with session management.

Upon authentication the application server returns a cookie with an auth token representing the server session. When I run the JS application off of my filesystem (file://) I can see that once client receives the cookie, it is sent in all the subsequent API requests. When I run the JS app on the node server and API calls are proxied through node-http-proxy (RoutingProxy) the request headers never include the cookie.

Is there something I need to handle manually to support this type of session persistence through the proxy? I've been digging through the node-http-proxy code but it is a little over my head because I am new to Node. or:

var express = require('express'),
routingProxy = require('http-proxy').RoutingProxy(),
app = express.createServer();

var apiVersion = 1.0,
apiHost =,
apiPort = 8080;

function apiProxy(pattern, host, port) {
return function(req, res, next) {
if (req.url.match(pattern)) {
routingProxy.proxyRequest(req, res, {host: host, port: port});
} else {

app.configure(function () {
// API proxy middleware
app.use(apiProxy(new RegExp('/' + apiVersion + '/.*'), apiHost, apiPort));

// Static content middleware
dumpExceptions: true,
showStack: true


More From » node.js


I did what you are asking by manually looking at the response, seeing if it is a set-cookie, snipping off the JSESSSIONID, storing it in a variable, and passing it on all subsequent requests as a header. This way the reverse proxy acts as a cookie.

on('proxyReq', function(proxyReq){ proxyReq.setHeader('cookie', 'sessionid=' + cookieSnippedValue) 

[#86030] Monday, April 23, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.

Total Points: 117
Total Questions: 116
Total Answers: 116

Location: Bangladesh
Member since Sat, Jan 23, 2021
3 Years ago
maxinec questions