Node.js: отправка XML-ответа из разных файлов - PullRequest
0 голосов
/ 05 сентября 2011

Наличие XML-ответа, например:

app.post '/incoming', (req,res) ->
    console.log "Hello, incoming call!"
    message = req.body.Body
    from = req.body.From

    sys.log "From: " + from + ", Message: " + message
    twiml = '<?xml version="1.0" encoding="UTF-8" ?>\n<Response>\n<Say>Thanks for your text, we\'ll be in touch.</Say>\n</Response>'
    res.send twiml, {'Content-Type':'text/xml'}, 200

Могу ли я иметь разные. XML файлы и res.send их в зависимости от условий?

1 Ответ

3 голосов
/ 05 сентября 2011

Конечно; Вы используете Express, верно? Используйте res.sendfile:

app.post '/incoming', (req,res) ->
  console.log "Hello, incoming call!"
  message = req.body.Body
  from = req.body.From
  sys.log "From: " + from + ", Message: " + message
  if condition
    res.sendfile 'foo.xml'
  else
    res.sendfile 'bar.xml'
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...