2013-12-10 34 views

回答

5

你可以寫你自己的中間件,並指定req.headers像這樣:

grunt.initConfig({ 
    connect: { 
     server: { 
      options: { 
       middleware: function(connect, options) { 
        return [ 
         function(req, res, next) { 
          // If path has .json, accept json 
          if (url.parse(req.url).pathname.match(/\.json$/)) { 
           req.headers.accept = 'application/json'; 
          } 
          next(); 
         }, 
         // then serve a static folder 
         connect.static('base/folder/') 
        ] 
       }, 
      } 
     } 
    }, 
}); 
+0

這正是它。謝謝,凱爾。 –