donald
donald

Reputation: 23737

Node.js: Send XML response from different files

Having a XML response like:

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

Can I have different .XML files and res.send them depending on conditions?

Upvotes: 0

Views: 2408

Answers (1)

Trevor Burnham
Trevor Burnham

Reputation: 77416

Sure; you're using Express, right? Use 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'

Upvotes: 3

Related Questions