Angular6: Serving assets using CDN but not Index.html - SecurityError: Failed to execute 'replaceState' on 'History'
Angular6: Serving assets using CDN but not Index.html - SecurityError: Failed to execute 'replaceState' on 'History'
目标
在 CDN (CloudFront) 上提供除 index.html 之外的所有文件。因此,该应用程序在与资产不同的子域上提供服务。
问题
我使用 ng build --prod --aot --base-href https://mycdn.x.com
构建我的应用程序,然后将所有文件发送到我的 CDN。 nginx 服务器正在服务 index.html
发生的事情是在应用程序加载时,我收到以下错误:
Uncaught (in promise): SecurityError: Failed to execute 'replaceState' on 'History':
A history state object with URL 'https://mycdn.x.com/' cannot be created in a document with origin
'https://myapp.x.com' and URL 'https://myapp.x.com/page1/page2'.
备注
- 所有文件都加载了 200 个代码。
- CORS 是为 GET/HEAD 设置的 * origin。
如何在保持应用程序正常运行的同时从 CDN 提供所有资产?
找到解决方案,应该使用 --deploy-url
而不是 --base-href
。
ng build --prod --aot --deploy-url https://mycdn.x.com
目标
在 CDN (CloudFront) 上提供除 index.html 之外的所有文件。因此,该应用程序在与资产不同的子域上提供服务。
问题
我使用 ng build --prod --aot --base-href https://mycdn.x.com
构建我的应用程序,然后将所有文件发送到我的 CDN。 nginx 服务器正在服务 index.html
发生的事情是在应用程序加载时,我收到以下错误:
Uncaught (in promise): SecurityError: Failed to execute 'replaceState' on 'History':
A history state object with URL 'https://mycdn.x.com/' cannot be created in a document with origin
'https://myapp.x.com' and URL 'https://myapp.x.com/page1/page2'.
备注
- 所有文件都加载了 200 个代码。
- CORS 是为 GET/HEAD 设置的 * origin。
如何在保持应用程序正常运行的同时从 CDN 提供所有资产?
找到解决方案,应该使用 --deploy-url
而不是 --base-href
。
ng build --prod --aot --deploy-url https://mycdn.x.com