简体   繁体   中英

Output html from CouchDB list

I am trying to create a list in CouchDB 0.11 which responds with some html, I am having problems getting CouchDB to set the correct header, whatever I try, I just get an application/json response header. Here is my list function.

function(head, req) {

    var rows = [];
    var row;

    while(row = getRow()) {
        rows.push(row);
    }

    rows.sort(function(a, b) {
        return (Date.parse(a['value']['last_logtime']) - Date.parse(b['value']['last_logtime']));
    });

    provides("html", function() {
        var content = "<html><head><title>foobar</title></head><body>";
        for(var i in rows) {
            content = content + rows[i]['value']['last_logtime']+"<br/>";
        }
        content = content + "</body></html>";
        return content;
    });

}

Any suggestions what I am doing wrong?

well actually figured it out myself.

the getRow() stuff needs to be inside the provides function :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM