0

I have the following node server:

var express = require('express');
var app = express();
var path = require('path');

app.set('port', (process.env.PORT || 5000));

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

// views is directory for all template files
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');

app.get('/', function(request, response) {
  response.render('pages/index');
});

app.get('/abstract', function(request, response) {
    response.render('pages/abstract');
});

app.get('/PCA', function(request, response) {
    response.render('pages/PCA');
});
... 

Below are my files where app.js is:

  • views
    • pages
      • index.ejs
      • abstract.ejs, etc.
    • partials
      • header.ejs
      • nav.ejs
  • public
    • css
      • main.css
    • img
      • logo.png
      • linear.png

After pushing to heroku, images on the "/" route are rendered. However, on '/abstract' '/PCA', only the images in the nav.ejs are showing up and all other images are not found. My css static file is found on all files. I've tried without success:

<img src="linear.png" id="linear"/>
<img src="img/linear.png" id="linear"/>
<img src="/img/linear.png" id="linear"/>

Thanks for you help!

  • Is that third `src` tag a typo (it should be `/img/linear.png` instead of `/imglinear.png`) or did you really try that? – mscdex Dec 10 '15 at 18:13
  • sorry that was a typo – Andriana Romero Dec 10 '15 at 19:18
  • @mscdex I'm not sure why only images on the "/" directory is rendering, so I think it might have to do with how I'm routing the app. I am new to express, but I've followed many examples like http://stackoverflow.com/questions/5924072/express-js-cant-get-my-static-files-why – Andriana Romero Dec 10 '15 at 19:31
  • do the images show up when you are working on the application locally? – AfDev Dec 10 '15 at 20:51
  • yup perfectly fine... I can't really explain why. When I git push heroku master, the sourced are pushed. – Andriana Romero Dec 11 '15 at 01:28

0 Answers0