gpt4 book ai didi

javascript - 使用 Apache 作为后端 JavaScript (Strapi) 服务器的代理

转载 作者:行者123 更新时间:2023-11-30 19:47:55 24 4
gpt4 key购买 nike

我正在尝试设置 Strapi.io 安装,以便它可以在端口 80 上运行的现有 Apache 站点上运行。

详细信息:

  • Strapi 服务器在端口 1337 上运行。
  • Strapi 服务器在/有一个首页和一个管理面板/admin
  • 我的 Apache 站点运行在 http://example.com在端口 80 上

我已经编辑了我的 apache 配置文件并添加了以下几行:

ProxyPass /admin http://localhost:1337/admin
ProxyPassReverse /admin http://localhost:1337/admin

ProxyPass /api http://localhost:1337/
ProxyPassReverse /api http://localhost:1337/

目前这适用于/api 页面,但不适用于管理页面。在管理页面上,我收到以下控制台错误:

main.js:40 Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0 at r (main.js:40) r @ main.js:40 Promise.then (async) u @ main.js:1 ./node_modules/strapi-helper-plugin/lib/src/app.js @ main.js:40 t @ main.js:1 (anonymous) @ main.js:1 (anonymous) @ main.js:1

main.js:45 Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0 at t (main.js:45) t @ main.js:45 Promise.then (async) u @ main.js:1 ./node_modules/strapi-helper-plugin/lib/src/app.js @ main.js:45 a @ main.js:1 (anonymous) @ main.js:1 (anonymous) @

main.js:1 main.js:40 Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0 at n (main.js:40)

如果我刷新页面,部分或全部 main.js 显示为 admin.js。不确定它是否有所作为:

main.js:40 Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0 at r (main.js:40) r @ main.js:40 Promise.then (async) u @ main.js:1 ./node_modules/strapi-helper-plugin/lib/src/app.js @ main.js:40 t @ main.js:1 (anonymous) @ main.js:1 (anonymous) @ main.js:1

admin:1 Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0 Promise.then (async) u @ main.js:1 ./node_modules/strapi-helper-plugin/lib/src/app.js @ main.js:40 t @ main.js:1 (anonymous) @ main.js:1 (anonymous) @ main.js:1

admin:1 Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0

为什么我会遇到这个问题。我需要做什么才能让它在我的 Apache 服务器上正常工作?

澄清:

这是一个非常简单的两分钟安装。我还没有开始向网站添加任何内容。我只是想让管理面板通过 Apache 工作。

最佳答案

Apache 默认提供 index.html 来响应它收到的任何请求。

因此,我的第一个想法是添加

DirectoryIndex disabled 

到 .htaccess,因为 strapi.io API 在 / 运行根文件夹和 apache 返回默认的 Apache .html 文件,这将覆盖 API 请求。

那里到底发生了什么?

1.- 您的 JavaScript 应用程序 (strapi.io) 请求 data.json在您的 API 点,它获取 index.html 的内容。

2.- 由于 index.html 的内容不是 JSON,并且以 < 开头,它会抛出错误消息。 JSON 文件不能以 < 开头.

关于javascript - 使用 Apache 作为后端 JavaScript (Strapi) 服务器的代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54778567/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com