0

So i am not sure why hopefully someone can explain this to me:

When i browse to / i get the err in the console from the /:summoner route i am confused why this is happening, i would have thought that browsing / would ONLY execute whats in / right?

var
  express = require('express'),
  AWS = require('aws-sdk'),
  router = express.Router();

AWS.config.loadFromPath('./config.json');
var s3 = new AWS.S3();

router.get('/', function(req, res) {
    res.render('index', { region: 'Oceania!' });
});

router.get('/:summoner', function(req, res) {
    var params = {Bucket: 'summonerdata', Key: '347341'};
    s3.getObject(params, function(err, data) {
        if (err) console.log(err, err.stack); // an error occurred
        else     console.log(data);           // successful response
    });
});

router.post('/search', function(req, res) {
    res.redirect('/' + req.body.summonerName);
});

module.exports = router;

1 Answers1

0

You should log exactly what is being requested by the browser, but it is most likely the browser asking for /favicon.ico, the little glyph that the browser likes to display next your URL. This is requested automatically by most browsers unless your web page has a directive not to ask for it.

Community
  • 1
  • 1
jfriend00
  • 683,504
  • 96
  • 985
  • 979
  • Umm, i dont see how that relates to my problem –  Feb 25 '17 at 07:12
  • @Elevant - when the browser requests `/favico.ico`, it's going to hit this route `router.get('/:summoner', ...)` with a value you aren't expecting. – jfriend00 Feb 25 '17 at 07:20
  • Aahhhh riight coz its automatically trying to find the default icon? –  Feb 25 '17 at 07:25
  • How do i go around it? –  Feb 25 '17 at 07:26
  • @Elevant - The link in my answer shows you what you can put in your web page to prevent the favicon request or you can just put an `app.get('/favicon.ico', ...)` route handler before your `router.get('/:summoner', ...)` handler and that will keep the favicon request out of your summoner handler. – jfriend00 Feb 25 '17 at 07:28
  • So i tried to get it to work and the favicon shows but the route problem still occurs: var favicon = require('serve-favicon'); app.use(favicon(path.join(__dirname,'public','images','favicon.png'))); –  Feb 26 '17 at 07:59