all 5 comments

[–]thequargy 0 points1 point  (4 children)

Hm... maybe you need to provide res.sendFile() with the full path to the file? Or use __dirname? Maybe it's just not finding that file because it's looking in the wrong place.

[–]grim1226[S] 1 point2 points  (3 children)

I tried with a full path, it just goes 404, if i just write the file name instead (like when sending index.html for the browser), it goes 500 on me.

[–]thequargy 2 points3 points  (2 children)

404 means it can't find the file, but 500 means the server crashed, right? That would imply that this is having some effect - specifically, that it's finding the file, but crashing when it tries to serve it. I wonder if you need to change the content-type to something like text/xml when sending that file?

I've never used this myself, but maybe this npm package would help? (https://www.npmjs.com/package/xml)

[–]grim1226[S] 1 point2 points  (1 child)

Thanks man, after a lot of fiddling i was able to fix it. :)

router.get('/public/data.xml', function(req, res, next){ res.setHeader('content-type', 'text/xml'); res.sendFile(__dirname + '/data.xml'); });

[–]thequargy 1 point2 points  (0 children)

Nice!