【发布时间】:2019-06-07 17:04:23
【问题描述】:
我有一个使用 node.js、express 和 socket.io 创建的小型聊天应用程序项目。并使用 npm 安装这些模块。应用程序按预期在桌面上运行。我正在尝试使用 cordova 构建应用程序的 android 版本。当我运行cordova run android 时,它会在我的手机上打开应用程序并毫无问题地加载主用户界面,但它确实不起作用(功能),我在 Chrome 开发人员控制台远程设备中收到此 错误, 当我在 index.html 中添加这样的 socket.io js 文件时
<script src="/socket.io/socket.io.js"></script>
socket.io.js:1 加载资源失败:net::ERR_FILE_NOT_FOUND
由于应用程序在 localhost 上的端口 3000 上运行,因此我尝试在 index.html 中添加这样的 socket.io js 脚本
<script src="http://localhost:3000/socket.io/socket.io.js"></script>
然后出现这个错误
拒绝加载脚本“http://localhost:3000/socket.io/socket.io.js”,因为它违反了以下内容安全策略指令:“script-src 'self' http://* 'unsafe-inline' 'unsafe-eval'”。
这是 Content-Security-Policy 元标记
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' http://* 'unsafe-inline'; script-src 'self' http://* 'unsafe-inline' 'unsafe-eval'" />
【问题讨论】:
标签: android node.js cordova sockets socket.io