【问题标题】:How to add header config using staticfile_buildpack for Angular app?如何使用 Angular 应用程序的 staticfile_buildpack 添加标头配置?
【发布时间】:2020-03-31 01:55:01
【问题描述】:

我使用ng build --prod 创建了一个构建。它创建了一个dist/AppName 文件夹,里面有我的 manifest.yml 和 Staticfile。当我在dist/AppName 内执行cf push 时,一切正常,但我想添加add_header 'Access-Control-Allow-Origin' '*'(nginx 配置)的标头配置,但我不知道如何在Staticfile 中执行此操作。我得到了一些线索,比如使用location_include,但是关于它的文档有点令人困惑。有人可以帮助或指导我如何做到这一点。谢谢。

【问题讨论】:

标签: angular nginx cloud-foundry pcfdev


【解决方案1】:

我通过查看相同的 staticfile-buildpack fixtures on github 设法解决了我的问题。 当我做ng build --prod Angular 时,将编译后的代码放入dist/AppName。在dist 文件夹中,我放置了manifest.ymlStaticfile 并添加了一个新文件夹nginx/conf/includes。新文件夹是我放置 headers.conf 的地方,其中包含 add_header nginx 指令。

所以dist有以下文件和文件夹

dist
  |_ AppName/
  |_ nginx/
  |   |_ conf
  |       |_ includes
  |           |_ headers.conf 
  |_ manifest.yml
  |_ Staticfile 

静态文件有以下内容:

pushstate: enabled
root: AppName
location_include: includes/*.conf

manifest.yml:

---
applications:
- name: appname-dev
  memory: 512M
  disk_quota: 1024M
  instances: 1
  timeout: 90
  buildpack: staticfile_buildpack

我在dist 文件夹中创建了cf push

【讨论】:

    猜你喜欢
    • 2014-07-30
    • 1970-01-01
    • 2022-10-17
    • 1970-01-01
    • 2021-03-12
    • 2013-04-04
    • 1970-01-01
    • 2014-07-11
    • 1970-01-01
    相关资源
    最近更新 更多