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

Ste*_*eve 9 gruntjs grunt-contrib-connect

我已经设置了像这样的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简单地完成吗?或者我是否需要添加其他代理/中间件?

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

All*_*sen 10

是的,你可以毫不费力地做到这一点,只需配置open选项:

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

有关可用选项的更多信息,请参阅自述文件.

  • 似乎它确实需要重写.我设法按照这里的例子开始工作:https://github.com/viart/grunt-connect-rewrite - 在规则如:{from:'^/myappcontext/secured /(.*)$',到:'/ $ 1'} (2认同)