2011-09-05 58 views
0

有一个XML响应,如XML响应:的Node.js:发送从不同的文件

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他们取决于条件?

回答

3

当然;你正在使用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' 
相关问题