Bomin
Bomin

Reputation: 1667

"index.html" is not served by grunt-contrib-connect

My code is pretty simple, and the grunt file is,

module.exports = function(grunt) {

   var proxySnippet = require('grunt-connect-proxy/lib/utils').proxyRequest;

   grunt.initConfig({
      connect: {
         server: {
            options: {
               hostname: "localhost",
               keepalive: true,
               base:['../web/'],
               port: 8080,
               middleware: function(connect, options) {
                  return [proxySnippet];
               },
               debug: true
            }
         }
      }
   });

   // grunt.loadNpmTasks('grunt-connect-proxy');
   grunt.loadNpmTasks('grunt-contrib-connect');

   grunt.registerTask('default', [

      'connect:server'
   ]);

};

there's an index.html, and the path is "../web/index.html". When I open

"http://localhost:8080"

it gives "Cannot GET /". Any idea why this is happening?

Upvotes: 0

Views: 817

Answers (2)

kunalprompt
kunalprompt

Reputation: 5

For directory structure like the following:

-node_modules
-templates
---index.html
---login.html
-Gruntfile.js

connect: {
         options: {
                port: 9000,
                livereload: true,
                hostname: 'localhost',
         },
         livereload: {
              options: {
                    open: true,
                    base: ['templates/']
              }
         }
    }

This open the complete directory structure of templates on the browser to navigate to any html page.

Upvotes: 1

Jesús Quintana
Jesús Quintana

Reputation: 1813

Remove the middleware proxy, like this:

module.exports = function(grunt) {

   var proxySnippet = require('grunt-connect-proxy/lib/utils').proxyRequest;

   grunt.initConfig({
      connect: {
         server: {
            options: {
               hostname: "localhost",
               keepalive: true,
               base:['../web/'],
               port: 8081,

               debug: true
            }
         }
      }
   });

   // grunt.loadNpmTasks('grunt-connect-proxy');
   grunt.loadNpmTasks('grunt-contrib-connect');

   grunt.registerTask('default', [

      'connect:server'
   ]);

};

And must work.

Upvotes: 0

Related Questions