mardi 22 décembre 2015

Confused about request path being sent to my Express server from AJAX

I have a basic setup for Node.js Express server

I am try to serve html files using res.sendFile, using this route handler:

router.get('/:run_id/:test_num',function(req,res,next){

    var runId = req.params.run_id;
    var testNum = req.params.test_num;

    res.sendFile(path.resolve('results',runId,testNum),{
        maxAge:'58h'
    });

});

in my app.js file, I have this middleware

app.use('/results', require('./routes/results'));

the problem is that the request is being routed like so:

  pathname: '/results/results/1450830953375/test6.txt',
  path: '/results/results/1450830953375/test6.txt',
  href: '/results/results/1450830953375/test6.txt' 

so the problem is that it is /results/results/ instead of just /results

I am using RequireJS and the module that contains the data of the files to be request looks like this:

    define('SumanTestFiles',function(){
            return new Object(["results/1450830340344/test5.txt","results/1450830340344/test6.txt"]);
     });

and then I loop over each file path and request it from the server using jQuery/AJAX:

define(['SumanTestFiles'],function(stf){

    stf.forEach(function (testPath) {
        $.get(testPath).done(function (msg) {...

so you can see that the testPaths have not been tampered with, they without a doubt simply "results/1450830340344/test5.txt", or the like.

so my question is, why does the path show up on my server with two adjacent 'results' string instances in the path?

It does not make a lot of sense, because the request should just be

/results/1450830953375/test6.txt

not

/results/results/1450830953375/test6.txt

anyone have any ideas? thanks




Aucun commentaire:

Enregistrer un commentaire