首页 > 解决方案 > 部署 Angular 7 网站和谷歌应用引擎 API 时的应用 yaml 配置问题

问题描述

我正在尝试在 Google App Engine 中部署一个 Angular7 应用程序,并在 python2.7 中使用后端端点。在这里我收到处理程序错误:

找不到处理程序引用的静态文件:dist/_ah/api/sampleApi/v1/users

在 app.yaml 中配置时,Angular 的 dist 文件夹和 API 都会失败。

如果从 app.yaml 中删除 API 的配置,则 Angular 网站可以正常工作。如果邮递员从 app.yaml API 的工作中删除了 Angular dist。

handlers:     
- url: /        
  static_files: dist/index.html         
  upload: dist/index.html      
  secure: always       
- url: /       
  static_dir: dist      
- url: /_ah/api/.*    
  script: sample.api   

我的项目结构是:

project-folder   
   -- app.yaml    
   -- endpoint source code files    
   -- dist folder (for angular)    

标签: python-2.7google-app-enginegoogle-cloud-platformangular7

解决方案


我通过在我的 app.yaml 文件中添加两个额外的处理程序来解决这个问题:

  • url: /(..(html|gif|png|jpg|js))$
    static_files: dist/\1
    上传: dist/.
    .(html|gif|png|jpg|js)$
    安全:总是
  • url:/img
    static_dir:dist/assets
    安全:总是

它现在正在工作。


推荐阅读