【问题标题】:Vapor `Public` directory inside docker image is not exposed泊坞窗图像内的蒸气“公共”目录未暴露
【发布时间】:2021-07-11 21:25:30
【问题描述】:

我在我的 Mac 上使用 Xcode 运行 Vapor 4.3 和 Leaf,没有任何问题。

公共目录中间件已启用:

let fileMW = FileMiddleware(publicDirectory: directory)
app.middleware.use(fileMW)

一旦我使用默认的dockerfile 构建图像并在 docker 上运行它,css 和所有图像文件都不再加载。

注意:dockerfilevapor new 命令所提供的完全相同。 (更新到写这篇文章的日期)

Safari 显示此错误:

[Error] Did not parse stylesheet at 'http://127.0.0.1/styles/index.css' because non CSS MIME types are not allowed in strict mode.

Chrome 显示此警告:

Resource interpreted as Stylesheet but transferred with MIME type text/plain: "http://127.0.0.1/styles/index.css".

我错过了什么?

【问题讨论】:

  • 只是为了确认您的 Dockerfile 是什么样的?如果您尝试卷曲文件而不是使用浏览器,您会看到什么?
  • vapor new 命令附带的默认 docker 文件完全相同。使用 curl 获取 404。 @0xTim
  • Dockerfile 几个月来发生了变化,因此您可能有一个需要更改的旧版本。你在Public/styles 中有一个名为index.css 的文件吗?最后你可以扩展let fileMW = FileMiddleware(publicDirectory: directory) - 那里的目录属性是什么?

标签: xcode docker dockerfile vapor leaf


【解决方案1】:

看起来这是一个区分大小写的问题! Mac 可以找到有此问题的文件,但 Linux 没有!

⚠️即使你已经设置了:app.routes.caseInsensitive = true,也不会影响你的资源请求。

因此,请确保您已将所有路径设置为与 pwd 命令中显示的完全一致。

【讨论】:

    猜你喜欢
    • 2019-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-29
    • 2018-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多