2

I have a static page set up to point to my images directory that is being pulled by a website on a separate server. For some reason, when I go directly to the image URL the image loads up (Chrome) and if I refresh the page it gives me an error like this:

Cannot GET /users/picture

My app.js has this:

var app = express();
    app.disable('view cache');
    app.use(express.static(__dirname + '/public')); //setup static public directory
    app.use('/users/picture', express.static('./public/images/users'));

... 

Plus some routes and other things like multer() for picture uploads.

For some reason if I refresh the page on the production server on Bluemix, the picture loads every third time. Otherwise it gives me this Cannot GET route error.

Could it be related to the memory?

Peter Poliwoda
  • 563
  • 2
  • 7
  • 19

2 Answers2

2

This can happen if you accidentally bind multiple applications to the same route. The router/load balancer is picking the other application on some requests. Confirm all your applications are bound to the correct unique routes in the bluemix dashboard or by doing cf apps

Ram Vennam
  • 3,536
  • 1
  • 12
  • 19
  • 1
    You sir deserve a big fat beer. There has been two applications bound to the same route and cf apps listed them perfectly. – Peter Poliwoda Jul 05 '15 at 13:59
0

I was facing the same issue. I followed the step mentioned here

Move the static middleware to the top of app.configure function, before all the other app.* calls.

app.use(express.static(__dirname + '/public'));

In my case, I wanted to serve a different folder. So I moved that above line, just below:

var app = express();
app.use(express.static(path.join(__dirname, 'myRootFolder', 'myActualPublicFolder')));
Community
  • 1
  • 1
Mahesh
  • 3,727
  • 1
  • 39
  • 49