How to return static xml file from nodejs server

I integrate a third-party template that has a slide show written using Mootools. Js node configured with expression and ejs

The data for the slide show comes from several XML files. For example, data.xml. I put data.xml in a shared folder and added the following code to server.js (main file)

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

app.post('/data.xml', function(req, res){
    res.contentType('application/xml');
    res.sendFile('/data.xml');
});

Unfortunately this does not work. I can see the file if I type the URL http: // localhost: 8080 / data.xml

But the answer I see in firebug is Msgstr "Cannot POST / data.xml"

I assume that Mootools is trying to access the file using some POST method. Any suggestions on this issue?

+4
source share
1

sendFile(), , . , data.xml .

localhost: 8080/data ( localhost: 8080/data.xml), , , . . , , , .

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

// you don't need this line!
// app.use(express.static(path.join(__dirname)));


app.post('/data', function(req, res){
    res.contentType('application/xml');
    res.sendFile(path.join(__dirname , 'data.xml'));
});



var server = app.listen(8080, () => {
	console.log('Started listening on 8080');
});
0

Source: https://habr.com/ru/post/1627256/


All Articles