【问题标题】:Node js with socket io application带有套接字 io 应用程序的节点 js
【发布时间】:2018-10-27 10:54:44
【问题描述】:

我在.htaccess 中加入了以下几行:

#Header set Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type"
Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"#

我可以在http://www.example.com 上运行带有套接字 io 应用程序的节点 js,但是当我尝试在 https://www.example.com 上运行时 我收到"Access-Control-Allow-Origin" header is present on the requested resource 的错误。我尝试在 CentOS 上创建一个虚拟主机,托管在 /etc/httpd/conf.d/httpd.conf 的 Apache Web 服务器上。当我打开一个像 3000 这样的非标准端口并监听它时,运行“端口已在使用”时出现错误。我该怎么办?

【问题讨论】:

    标签: javascript node.js apache socket.io virtualhost


    【解决方案1】:

    你应该在你的 node express 服务器上实现 cors!

    https://en.wikipedia.org/wiki/Cross-origin_resource_sharing

    或者你可以尝试为https://github.com/agrueneberg/Corser实现包

    【讨论】:

      猜你喜欢
      • 2020-09-25
      • 1970-01-01
      • 1970-01-01
      • 2015-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-28
      • 1970-01-01
      相关资源
      最近更新 更多