使用请求将文件上载到CouchDB的Grunt任务

时间:2014-06-09 14:29:44

标签: coffeescript gruntjs couchdb

在我的Gruntfile.coffee中,我设置了一项任务:

grunt.registerTask 'couch_upload', 'CouchDB upload', ->
  done = @async()

  assets = ['combined.min.js', 'screen.min.css']
  ddoc = 'http://localhost:5984/mydb/_design/app'
  request = require 'request'
  fs = require 'fs'
  grunt.log.writeln 'Uploading assets...'

  upload = (asset) ->
    # get the revision of the design document
    request.get {json: yes, url: ddoc}, (err, resp, body) ->
      rev = body._rev
      # stream the file and pipe it, so it has the correct Content-Type
      fs.createReadStream('build/' + asset).pipe request.put
        auth: user: 'myusername', password: 'mypass'
        headers: 'If-Match': rev
        url: [ddoc, asset].join '/'
      , -> grunt.log.write ' ' + asset

  upload asset for asset in assets

  done()

但我无法看到任何上传内容,无论是在Grunt的日志上,还是在Couch的日志中。

你能说出我做错了吗?

1 个答案:

答案 0 :(得分:0)

听起来你需要向CouchDB-Lucene打开一个功能请求:https://github.com/rnewson/couchdb-lucene/issues - 它似乎没有启用该功能,如果可能的话。