node.js - How do I configure grunt-connect-proxy with grunt serve? -


i managed configure grunt serve application, since serves on localhost:9000, api calls go port 9000 while api @ port 3000, resulting in 404 error.

after research, i've decided need use grunt-connect-proxy proxy api calls right port. i've been beating head against wall going through every article, stack overflow question , documentation, can't seem configuration right. see gruntfile below. have undying gratitude.

// invoke 'strict' javascript mode 'use strict';  module.exports = function(grunt) {     require('matchdep').filterdev('grunt-*').foreach(grunt.loadnpmtasks);     grunt.initconfig({         less: {             development: {                 options: {                     compress: true,                     yuicompress: true,                     optimization: 2,                     paths: ['public/styles/less']                 },                 files: {                     "public/styles/css/main.css": "public/styles/less/main.less" // destination file , source file                 }             }         },         watch: {             styles: {                 files: ['public/styles/less/*.less'],                 tasks: ['less'],                 options: {                     nospawn: true                 }             }         },         connect: {             server: {                 options: {                     port: 8000,                     base: 'public',                     logger: 'dev',                     hostname: 'localhost',                     middleware: function (connect, options, defaultmiddleware) {                         var proxy = require('grunt-connect-proxy/lib/utils').proxyrequest;                         return [                             // include proxy first                             proxy                         ].concat(defaultmiddleware);                     }                 },                 proxies: [                     {                         context: '/',                         host: '127.0.0.1',                         port: 3000,                         https: false,                         xforward: false,                         headers: {                             "x-custom-added-header": 'value'                         },                         hideheaders: ['x-removed-header']                     }                 ]             },             serve: {                 options:{                     port: 9000,                     hostname: "127.0.0.1",                     middleware: function(connect, options) {                     return [                         require('grunt-contrib-livereload/lib/utils').livereloadsnippet,                         connect.static(options.base[0])                     ];                 }             }         }     },     open: {       serve: {         path: 'http://localhost:<%= connect.serve.options.port%>/public'       }     },     regarde: {         serve: {             files:['public/index.html','public/script/*.js','public/script/**/*.js','public/styles/**/*.css','public/styles/less/*.less','public/views/*.html'],             tasks: ['livereload']         }     } });  grunt.loadnpmtasks('grunt-contrib-watch'); grunt.loadnpmtasks('grunt-contrib-less'); //grunt.loadnpmtasks('grunt-contrib-clean'); //grunt.loadnpmtasks('grunt-contrib-compass'); grunt.loadnpmtasks('grunt-connect-proxy');  grunt.registertask('serve',['less','livereload-start','connect:serve','open:serve','regarde:serve']); grunt.registertask('server', function (target) {     grunt.task.run([         //'clean:server',         //'compass:server',         'configureproxies:server',         'connect:server',         'watch'     ]); }); 

};


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -