angular - 如何从 Go HTTP Server 为 Angular 应用程序提供服务?

标签 angular go

我正在尝试从用 Go 编写的服务器提供 Angular 应用程序 (Angular 8.2.14)。

四处搜索,我发现了以下片段,据说可以解决这个问题。

func main() {
    http.ListenAndServe(":4000", http.FileServer(http.Dir(folderDist)))
}

其中folderDist是我对应用程序进行ng build的目录。

当我在示例中导航到 localhost:4000 时,我在浏览器上收到以下错误:

runtime-es2015.js:1 Failed to load module script: The server responded with a non-JavaScript MIME type of "text/plain". Strict MIME type checking is enforced for module scripts per HTML spec.
styles-es2015.js:1 Failed to load module script: The server responded with a non-JavaScript MIME type of "text/plain". Strict MIME type checking is enforced for module scripts per HTML spec.
main-es2015.js:1 Failed to load module script: The server responded with a non-JavaScript MIME type of "text/plain". Strict MIME type checking is enforced for module scripts per HTML spec.
polyfills-es2015.js:1 Failed to load module script: The server responded with a non-JavaScript MIME type of "text/plain". Strict MIME type checking is enforced for module scripts per HTML spec.
vendor-es2015.js:1 Failed to load module script: The server responded with a non-JavaScript MIME type of "text/plain". Strict MIME type checking is enforced for module scripts per HTML spec.

我错过了什么?

我已经尝试过解决方案 suggested here ,但错误还是一样。

最佳答案

已解决。

显然 Angular 8 的某些版本中存在错误...

编辑tsconfig.json文件并将“target”行更改为“es5”。

"target": "es5",

制作“ng build”。

完成!

关于angular - 如何从 Go HTTP Server 为 Angular 应用程序提供服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59306919/

相关文章:

mongodb - 使用 mgo 或 bson 在 Go 中重命名 mongo 集合?

go - 如何打印 os.args[1 :] without braces in Go?

java - 在 Go 中将 C.jstring 转换为 native 字符串

javascript - TypeScript 中的 findIndex 数组方法

angular - 两个 Angular 4 应用程序之间的通信

angular - 在 Angular2 中动态更新 [checked]

reflection - 通过接口(interface)访问嵌入式类型字段

azure - 按订阅 ID 获取 Azure 组织

css - Mat-form-field 在不同的浏览器中有不同的高度

Angular 6 Material - 组件不是已知元素