javascript - Heroku 部署:单页应用程序作为前端和表达作为后端
问题描述
我尝试在 Heroku 上部署我的应用程序。
我的堆栈:
后端:Express + Mongodb + Typescript
前端:Express + Vanilla JS(单页应用)
后端已部署并且工作正常,问题出在前端。我希望我使用过 React,因为使用 React 我会知道该怎么做。问题是香草 JS。我必须说一切都在我的本地主机上运行,所以在 Heroku 部署之后存在问题。
在我的index.html
我有这一行:
<script type="module" src="/static/javascript/index.js"></script>
我在 Heroku 应用程序html
中从index.html
, nocss
和控制台中看到该错误:Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.
我认为这是因为 Heroku 尝试进行本地化https://my-app.herokuapp.com/static/javascript/index.js
。如何告诉 Heroku 将此路径视为带有模块的子文件夹,而不是本地化?
当我使用 React 时,我告诉package.json
构建前端npm run build
,在 Vanilla JS 中用什么替代它?如何说 Heroku 这是 Vanilla JS 并构建它?
解决方案
推荐阅读
- python - 如何在 PYTHON 中打开文件并使用正则表达式修改其内容以查找/匹配/替换模式
- ruby-on-rails - 对于 CVE-2021-22885,是否只对数组内容有危险?
- javascript - 当 Facebook 列出我的故事的故事查看者数量时,我如何在源代码中查看他们的计数?
- javascript - 无限循环输出数组中的所有值
- redis - 通过`node-redis`关闭Redis服务器的正确方法是什么?
- sql - 查找每个属性值的行数,仅考虑 SQL 中最近的行
- reactjs - React 从同时渲染的另一个元素中获取元素尺寸
- ios - Corebluetooth - 在 iOS14 上保持连接
- reactjs - 从 '.' 导入 x 不在 react-native(expo) 项目中工作
- python - 我可以在 python 中的单个 if 语句中打印两个具有不同条件的语句吗?