【问题标题】:Grunt: is there a way to load a determinate file or url, based on current pathGrunt:有没有办法根据当前路径加载确定的文件或 url
【发布时间】:2016-09-10 02:01:41
【问题描述】:

我正在构建一个站点,在某种情况下,用户将通过 url 中的一些参数访问该站点。像这样的:

http://example.org/params/param1/param2

我需要 Grunt 来识别这个 url,并加载我读取这些参数的站点的 / 根目录。

我无法通过其他方式接收参数,

有没有办法解决这个问题?

编辑

connect: {
      options: {
        port: 9000,
        // Change this to '0.0.0.0' to access the server from outside.
        hostname: '0.0.0.0',
        livereload: 35729
      },
      livereload: {
        options: {
          open: true,
          middleware: function (connect) {
            return [
              connect.static('.tmp'),
              connect().use(
                '/bower_components',
                connect.static('./bower_components')
              ),
              connect().use(
                '/app/styles',
                connect.static('./app/styles')
              ),
              connect.static(appConfig.app)
            ];
          }
        }
      },

【问题讨论】:

  • 我不明白这与 Grunt 有什么关系。听起来您的网络服务器上需要 URL 重写规则。
  • 是的,没错,我是用grunt来运行server的,我需要为server重写规则
  • 你使用什么 Grunt 任务来启动你的服务器?
  • 我使用livereload,查看我上面添加的代码

标签: javascript gruntjs grunt-contrib-connect


【解决方案1】:

Livereload 不是这里的问题。您可能正在通过http://localhost 之类的网址查看您的网站,该网址指向其他地方的服务器实例(通过另一个 Grunt 命令或python -m SimpleHTTPServer/php -S localhost 等,或 Apache、Nginx 等) .无论软件是什么,都需要这种配置。如果您需要帮助,请针对该软件提出另一个问题,我相信有人可以提供帮助!

【讨论】:

    猜你喜欢
    • 2021-01-09
    • 1970-01-01
    • 2022-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多