mime-types - 拒绝从 packs/js/index-662807e73049021453fe.js' 执行脚本,因为它的 MIME 类型('text/html')
问题描述
我使用 react/rails 部署了一个带有 aws ec2 实例的网站。通过 rails s -e production 运行服务器时,出现此错误
Refused to execute script from 'http://<ip-address>/packs/js/index-662807e73049021453fe.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
我的 application.erb.html
<!DOCTYPE html>
<html>
<head>
<title>Production server</title>
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
<%= javascript_pack_tag 'index' %>
</head>
<body>
<%= yield %>
</body>
</html>
我一直在寻找一个星期的答案。任何帮助将不胜感激。
更新:
我的路线以捕获 routes.rb 中的所有路线
root 'homepage#index'
get ':path', to: 'homepage#index', format: false
这指向主页视图
<%= javascript_pack_tag 'index' %>
<%= react_component("App", {prerender: true}) %>
解决方案
推荐阅读
- excel - 如何更改到下一行?
- sql-server - 使用 bcp 实用程序将逗号分隔的 txt 文件导入 sql server
- sql - 如何获取 mongodb 中的记录数
- ios - 如何在 Xcode 11.1 中创建 ipa 输出
- c# - 使用 WebClient 或类似方法从 .NET Framework 2.0 ASP.NET 应用程序获取 Azure AD 访问令牌
- javascript - useMemo 设置组件样式
- excel - 从用户表单输入填充 excel 列时如何防止重复?
- python - 如何在 Python 中对字典列表进行排序
- javascript - reactjs onclick 功能变化
- mysql - MySQL:根据不同的列减去不同的行