首页 > 解决方案 > 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 并构建它?

标签: javascriptnode.jsexpressherokudeployment

解决方案


推荐阅读