【问题标题】:Open JSON files in PhpStorm built-in web server在 PhpStorm 内置 Web 服务器中打开 JSON 文件
【发布时间】:2019-05-21 05:54:15
【问题描述】:

我尝试在 PhpStorm 中创建简单的 PWA。我有 2 个文件:

  • home.html
  • manifest.json

文件home.html 包含指向manifest.json 的链接:

<link rel="manifest" href="/manifest.json">

当我使用 PhpStorm 内置 Web 服务器打开 home.html 时,Chrome 控制台中的 manifest.json 出现错误 404:

Failed to load resource: the server responded with a status of 404 (Not Found)

我可以从上下文菜单在浏览器中打开home.html

manifest.json 没有这个选项:

我可以在 PhpStorm 中配置内置 Web 服务器以使用 JSON,或者这是不可能的吗?

【问题讨论】:

    标签: json configuration phpstorm built-in-web-server


    【解决方案1】:

    问题是由您的 URL (href="/manifest.json") 引起的:前导斜杠告诉浏览器从 Web 服务器根目录解析 URL。 内部 Web 服务器在使用“绝对”URL 时返回 404,因为它提供来自 localhost:port/project_name 而不是来自 localhost:port 的文件。如果您希望在内置 Web 服务器上托管您的应用程序时解析您的 URL,请使用相对于当前文件的 URL (href="path/relative/to/home.html/manifest.json")

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-10-24
      • 1970-01-01
      • 1970-01-01
      • 2020-05-08
      • 1970-01-01
      • 1970-01-01
      • 2014-07-16
      相关资源
      最近更新 更多