简体   繁体   English

Grunt返回Cannot GET /,ModRewrite不起作用

[英]Grunt returns Cannot GET/ , ModRewrite does't work

I'm very new to Grunt (started this Friday). 我是Grunt的新手(从本星期五开始)。 when I run Grunt Serve, it opens a page with just the words "cannot GET/" on it. 当我运行Grunt Serve时,它会打开一个页面,上面只有单词“ cannot GET /”。 I found the ModRewrite fix and implemented it. 我找到并实现了ModRewrite修复程序。 Yet when I try to get my grunt working, it still returns the same error. 但是,当我尝试使自己的咕unt声工作时,它仍然返回相同的错误。

Any help would be greatly appreciated 任何帮助将不胜感激

Here is my Gruntfile: 这是我的Gruntfile:

/* global module:true 
 * 
 * Gruntfile.js
 * npm install -g grunt-cli
 * npm install grunt-contrib-less grunt-contrib-watch grunt-contrib-connect --save-dev
 */
module.exports = function(grunt) {
    'use strict';

    var serveStatic = require('serve-static');

    var phpMiddleware = require('connect-php');

    var modRewrite = require('connect-modrewrite')

    grunt.initConfig({

      connect: {
        server: {
          options: {
            port: 8765,
            livereload: 35729,
            open: true,
            middleware: function(connect, options) {
              var middlewares;
              middlewares = [];

              middlewares.push( modRewrite( ['^[^\\.]*$ /index.html [L]'] ) );


              var directory = options.directory || options.base[options.base.length - 1];
              if (!Array.isArray(options.base)) {
                  options.base = [options.base];
              }

              // Magic happens here 
              middlewares.push(phpMiddleware(directory));

              options.base.forEach(function(base) {
                  // Serve static files. 
                  middlewares.push(serveStatic(base));
              });

              // Make directory browse-able. 
              //middlewares.push(connect.directory(directory));
              return middlewares;

            }
          }
        }
      }
      ,
      // Less files are in app/less, output is in app/css
      less: {
        development: {
          options: {
            paths: ["./less"],
            yuicompress: false
          },
          files: {
          "./css/style.css": "./less/style.less"
          }
        }
      },
      watch: {
        options: {
          livereload: 35729
        },
        files: "./less/*.less",
        tasks: ["less"]
      },

      uglify: {
        dist: {
            options: {
                sourceMap: 'js/map/source-map.js'
            },
            files: {
                'js/plugins.min.js': [
                    'js/source/plugins.js',
                    'js/vendor/**/*.js',
                    'js/vendor/modernizr*.js'
                ],
                'js/main.min.js': [
                    'js/source/main.js'
                ]
            }
          }
        }
      });

    grunt.loadNpmTasks('grunt-contrib-less');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-connect');
    grunt.loadNpmTasks('grunt-contrib-uglify');

    // Run grunt server to get going
    grunt.registerTask('serve', [
      'connect',
      'watch'
    ]);

    grunt.registerTask('server', function () {
      grunt.log.warn('The `server` task has been deprecated. Use `grunt serve` to start a server.');
      grunt.task.run(['serve']);
    });

  };

Changed middlewares.push( modRewrite( ['^[^\\\\.]*$ /index.html [L]'] ) ); 更改了middlewares.push( modRewrite( ['^[^\\\\.]*$ /index.html [L]'] ) );

to middlewares.push( modRewrite( ['^[^\\\\.]*$ /index.php [L]'] ) ); middlewares.push( modRewrite( ['^[^\\\\.]*$ /index.php [L]'] ) );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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