标签: grunt-contrib-connect

警告:connect.static不是函数使用--force继续

我正在使用YO lessapp项目,"grunt-contrib-connect"帮助我在9000端口上启动节点js服务器.每当我运行grunt serve(启动服务器)时,由于以下警告,服务将中止.

Running "connect:livereload" (connect) task
Warning: connect.static is not a function Use --force to continue.
Run Code Online (Sandbox Code Playgroud)

确切的错误发生在Gruntfile.js中的以下函数中

 livereload: {
        options: {
          middleware: function(connect) {
            return [
              connect.static('.tmp'),
              connect().use('/bower_components', connect.static('./bower_components')),
              connect.static(config.app)
            ];
          }
        }
      }, 
Run Code Online (Sandbox Code Playgroud)

我安装了 npm install grunt-contrib-connect --save-dev, npm install serve-static --save-dev

我发现了一些帖子,有些人建议关闭防火墙,但没有运气.

我知道我的机器或npm/node/connect版本冲突有关,因为我试图从其他机器运行相同的应用程序,它工作正常.

系统配置 :

  • Windows 7专业版
  • 节点-v4.1.2
  • npm -v2.14.4
  • connect@3.4.0

我已经安装了connect和serve-static,基于post nodejs connect无法找到静态,但仍然相同

有帮助吗?提前致谢

npm gruntjs grunt-contrib-connect

27
推荐指数
2
解决办法
2万
查看次数

具有keepalive true的grunt-contrib-connect中间件CORS解决方案

对于我的本地开发系统,我正在尝试使用grunt-contrib-connect提供前端资产.我需要一个跨域解决方案来在Firefox中使用字体.服务器运行得很好,但我似乎无法设置标头.

我使用的是grunt-contrib-connect的0.7.1版本.

connect: {
        dev: {
            options: {
                port: '9001',
                base: 'build',
                hostname: 'localhost',
                keepalive: true,
                middleware: function(connect, options, middlewares) {
                    // inject a custom middleware into the array of default middlewares
                    // this is likely the easiest way for other grunt plugins to
                    // extend the behavior of grunt-contrib-connect
                    middlewares.push(function(req, res, next) {
                        req.setHeader('Access-Control-Allow-Origin', '*');
                        req.setHeader('Access-Control-Allow-Methods', '*');
                        return next();
                    });

                    return middlewares;
                }
            }
        }
}
Run Code Online (Sandbox Code Playgroud)

使用keepalive和中间件有问题吗?

cors grunt-contrib-connect

14
推荐指数
1
解决办法
4254
查看次数

Grunt连接任务和中间件Access-Control-Allow-Origin

我想允许访问跨源调用,我需要能够对服务器执行其他API调用.

我的connect grunt任务配置如下:

    connect: {
  options: {
    port: 9000,
    // Change this to '0.0.0.0' to access the server from outside.
    hostname: 'localhost',
    livereload: 35729,
    middleware: function(connect, options, next) {
      return [
        function(req, res, next) {
          res.setHeader('Access-Control-Allow-Origin', '*');
          res.setHeader('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
          res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
          next();
        }
      ];
    }
  },
},
Run Code Online (Sandbox Code Playgroud)

当我运行grunt服务器时,我得到了Cannot GET /.没有中间件配置,应用程序正在运行,索引文件已正确加载.

你能指导我做错我做错了吗?

关于我的gruntfile的更多细节是我使用yeoman角度种子应用程序作为我的应用程序的基础.

javascript node.js angularjs gruntjs grunt-contrib-connect

11
推荐指数
1
解决办法
1万
查看次数

grunt-connect:提供添加了基本网址的文件

我正在使用grunt作为我的任务管理器开发基于jekyll的站点.我正在使用grunt-contrib-connect在本地提供我的文件以进行开发,因为它具有livereload功能.可以在浏览器中访问这些文件: http://localhost:8081/index.html

在我的服务器上,我的文件位于子目录中,因此在所有URL之前都有一个基本URL: http://path.to.server/mysite/index.html

我想不出用grunt-connect模拟我本地开发设置中的基本URL的方法.没有它,我不知道如何引用我的css或js文件,而服务器或我的开发盒上的网址无效.

我知道jekyll的serve函数可以添加一个基本URL,但它不会给我livereload功能.

有小费吗?

jekyll gruntjs grunt-contrib-connect

10
推荐指数
1
解决办法
3289
查看次数

Grunt连接服务器返回不能与骨干网进行GET /路由

我有一个在localhost上运行的连接服务器,在我的骨干应用程序中,如果我重新加载一个路由,说localhost:8000/fun服务器返回无法获取/乐趣显然因为/ fun不存在.

不知何故,服务器需要知道如何提供index.html/fun或其他东西.我实际上尝试过,但我得到了一些其他错误.以前有人处理过这个吗?

TL; DR无法获得/乐趣

javascript backbone.js gruntjs grunt-contrib-connect

9
推荐指数
1
解决办法
5360
查看次数

使用grunt-contrib-connect - 打开的页面URL和添加的上下文路径

我已经设置了像这样的grunt连接:

connect: {
    options: {
        port: 9000,
        livereload: 35729,
        hostname: 'localhost'
    },
    livereload: {
        options: {
            open: true,
            base: [
                'app'
            ]
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

效果很好 - 将我的index.html页面加载为:

http://localhost:9000
Run Code Online (Sandbox Code Playgroud)

但是,为了使其与生产中的加载方式保持一致,我希望它添加额外的上下文路径来加载它,例如:

http://localhost:9000/myappcontext/secured
Run Code Online (Sandbox Code Playgroud)

这可以通过grunt-contrib-connect简单地完成吗?或者我是否需要添加其他代理/中间件?

有人有这种类型设置的简单例子吗?

gruntjs grunt-contrib-connect

9
推荐指数
1
解决办法
1万
查看次数

通过grunt-contrib-connect在浏览器中显示PDF

我正在运行一个AngularJS应用程序,我正在使用该grunt-contrib-connect插件来托管我的东西.我想在浏览器中访问一些PDF文件(在所有这些文件中进行测试),但页面保持空白.但它确实显示了正确的页面数量.我使用Word和Pages从.doc文件导出PDF,但结果保持不变.

我写了这个小中间件片段以确保标题设置(根据Chrome的网络标签,它们是,但是页面保持空白.有帮助吗?

在我的Grunt文件中;

grunt.initConfig({
    settings: {}, // ...
    connect: {
        livereload: {
            middleware: function(connect) {
                var middlewares = [];
                // Other middlewares
                middlewares.push(function (req, res, next) {
                    if (~req.url.indexOf('.pdf')) {
                        res.setHeader('Content-type', 'application/pdf');
                    }
                    return next();
                });

                return middlewares;
            }
        } 
    } 
});
Run Code Online (Sandbox Code Playgroud)

pdf express gruntjs grunt-contrib-connect

7
推荐指数
1
解决办法
491
查看次数

Grunt服务器不使用虚拟主机名为我的app..vhost和httpd设置但grunt没有使用它们

所以我试图用名字设置我的应用程序,而不是使用127 0 0 1.每次我运行grunt,我的地址是http://127.0.0.1:9000/#/......我尝试了很多东西,没有任何工作...我总是被重定向到那个地方.

这是我的文件:

httpd.conf文件

<VirtualHost *:80>
    DocumentRoot "/Users/myusername/Sites/MyApp/app"
    ServerName myapp.dev
    <Directory "/Users/myusername/Sites/MyApp/app">
    Options FollowSymLinks MultiViews Indexes
    AllowOverride All
    Order allow,deny
    Deny from none
    Allow from all
    </Directory>
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

主机

127.0.0.1 myapp.dev
::1 myapp.dev
Run Code Online (Sandbox Code Playgroud)

Gruntfile.js

// Generated on 2013-11-08 using generator-angular 0.5.1
'use strict';

// # Globbing
// for performance reasons we're only matching one level down:
// 'test/spec/{,*/}*.js'
// use this if you want to recursively match all subfolders:
// 'test/spec/**/*.js'

module.exports = function (grunt) { …
Run Code Online (Sandbox Code Playgroud)

httpd.conf vhosts gruntjs yeoman grunt-contrib-connect

6
推荐指数
1
解决办法
5694
查看次数

获取livereload以使用Sails.js

我是Sails和grunt的新手所以我可能会错过这个明显的东西.我试图在文件发生变化时自动在浏览器中刷新我的风帆应用程序.

我启动应用程序,sails lift它在默认端口上运行1337.

我尝试添加options: {livereload:true}到我的grunt-contrib-watch配置,但据我所知,我需要以某种方式将livereload JavaScript注入我的页面?

我尝试使用注入JavaScript grunt-contrib-connectlivereload选项,但似乎只是启动另一台服务器.当我导航到启动的服务器(localhost:8000)时,我只看到文件夹结构.然而,注入了livereload JavaScript.

如果可能的话,我想避免使用livereload Chrome插件.

将livereload JavaScript注入我的Sails应用程序的最佳方法是什么?或者我应该使用像Browsersync这样的其他工具?

谢谢!:)

livereload grunt-contrib-watch sails.js grunt-contrib-connect browser-sync

5
推荐指数
1
解决办法
2979
查看次数

grunt-contrib-connect错误:中间件未定义

我正在为我的AngularJS应用程序使用yeoman的角度生成器.这个生成器包括grunt和grunt-contrib-connect,它们非常有用......但是依赖项已经过时了,所以我决定更新它们.

这样做时,我有一个grunt-contrib-connect错误,这是我使用--verbose选项的时候:

Running "connect:test" (connect) task
Verifying property connect.test exists in config...OK
File: [no files]
Options: protocol="http", port=9001, hostname="localhost", base=".", directory=null, 
keepalive=false, debug=false, livereload=35729, open=false, useAvailablePort=false, 
onCreateServer=null, middleware=undefined
Warning: undefined is not a function Use --force to continue.

Aborted due to warnings.
Run Code Online (Sandbox Code Playgroud)

所以似乎中间件负责这个问题,这里是:

middleware: function (connect) {
            return [
              connect.static('.tmp'),
              connect.static('test'),
              connect().use(
                '/bower_components',
                connect.static('./bower_components')
              ),
              connect.static(appConfig.app)
            ];
          }
Run Code Online (Sandbox Code Playgroud)

任何帮助我解决这个问题的帮助都非常受欢迎:)

gruntjs grunt-contrib-connect

5
推荐指数
1
解决办法
393
查看次数