Docker子文件夹安装因Ember-CLI代理错误无法工作?

(我已将此标记为#unsupported-install,但仍希望得到专家的意见 :slight_smile:

各位,我正尝试通过 Docker Compose 在一个相对简单的多 Docker 容器设置中运行一个基本的 Discourse 镜像。

基本情况如下:

  • 论坛位于一个子文件夹中,我们称之为 /board,所以 (https://blah.com/board)
  • nginx 将 /board:443 的请求转发到 localhost:4000
  • Discourse rails 运行在端口 4000 上(因为 3000 被其他东西占用了)
  • Rails ENVs 中包含一个至关重要的设置,用于实现此功能:
    DISCOURSE_RELATIVE_URL_ROOT: “/board”

现在我更新了 Discourse 的版本(Ember-CLI 之前),但东西不再工作了。

所以,我添加了一个 Ember-CLI 的容器,运行:

discourse-ember:
    command: bin/ember-cli --port 4000 --proxy "http://localhost:4200"

所以 Ember 现在首先处理进入 4000 端口的请求。

我将 Discourse rails 容器移动到端口 4200 并启动。

好消息:

  • curl 开发站点可以工作!

坏消息:

  • 在浏览器中无法工作,为什么?:
    因为它显然试图访问 Discourse,但请求的是:
    /bootstrap.json
    并给出错误:
Discourse Ember CLI Proxy Error
Error: Could not get http://0.0.0.0:4200/bootstrap.json

FetchError: invalid json response body at http://0.0.0.0:4200/bootstrap.json?for_url=%2Fboard reason: Unexpected token N in JSON at position 0

而不是
/board/bootstrap.json(它返回数据)。

如果我改用此配置:

  discourse-ember:
    command: bin/ember-cli --port 4000 --proxy "http://0.0.0.0:4200/forum"

我会收到一个 Rails 错误:

Routing Error
No route matches [GET] "/forum"

然而,在几行之外,它提供了:

bootstrap_path	GET	/bootstrap(.:format)
bootstrap#index {:format=>/(json|html|\*\/ \*)/}

这正是我试图访问的路径?

如何让 Ember 在尝试获取 bootstrap 信息时,能够智能地代理到子文件夹,即:

http://0.0.0.0:4200/forum/bootstrap.json

请记住,在此实例中,Ember 运行在自己的容器中。

1 个赞

您是如何构建容器的?您是从 docker-compose 启动该容器的吗?

有一个……嗯,一些环境变量设置……可以用来尝试阻止 ember-cli 工作;您移除它了吗?(我想它现在已经被忽略了?)

是的,这些容器定义在 docker-compose 中。

目前 ember-cli 容器中没有环境设置。

你是在使用 Serve Discourse from a subfolder (path prefix) instead of a subdomain 中的内容来构建容器和启动器,然后再让 docker-compose 启动它吗?

它是什么代理?也许只需使用启动器启动 discourse,然后使用 docker-args 设置其他需要的东西?对于 traefik,我这样做:

        --docker-args "-l traefik.frontend.rule=Host:{{discourse_hostname}};PathPrefix:/{{discourse_subfolder}} \
        -l traefik.frontend.entryPoints=https \
        -l traefik.backend={{discourse_shortname}} \
        -l traefik.port=80 \
        {{ docker_extra_args | default('')}}"
1 个赞

不,我只是在使用 Discourse Docker 镜像(版本 2.8.9)。

(实际上镜像托管在本地,但基本上是这样的:)

  discourse:
    command: bin/rails s -b 0.0.0.0 -p 4200
    image: discourse:v2.8.9
    environment:
      DISCOURSE_PORT: 4200
      DISCOURSE_RELATIVE_URL_ROOT: “/board”
     <SNIP>
    ports:
      - 4200:4200
  discourse-ember:
    command: bin/ember-cli --port 4000 --proxy "http://0.0.0.0:4200"
    image: discourse:v2.8.9
    ports:
      - 4000:4000

在这种情况下,我无法解释它以前是如何工作的。我认为您需要构建一个带有启动器的映像,该映像会添加支持子文件夹安装的内容。

已解决。

我的错,没有将此添加到 Ember CLI 容器中(它已经在 Rails 容器中):

DISCOURSE_RELATIVE_URL_ROOT: “/board”

哎呀 :sweat_smile:

供您参考,源文件中的关键文件我认为是这个:

3 个赞

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.