Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 刷新谷歌云应用引擎页面抛出404_Angular_Google App Engine_Google Cloud Platform - Fatal编程技术网

Angular 刷新谷歌云应用引擎页面抛出404

Angular 刷新谷歌云应用引擎页面抛出404,angular,google-app-engine,google-cloud-platform,Angular,Google App Engine,Google Cloud Platform,我们有一个Angular 6应用程序构建并部署到谷歌云应用程序引擎,该引擎运行正常。然而,任何时候浏览器刷新的路径不是应用程序的根,我们得到的是404 这是我们的app.yaml文件: runtime: nodejs8 handlers: - url: / static_files: dist/song/index.html upload: dist/song/index.html secure: always - url: /(.*) static_

我们有一个Angular 6应用程序构建并部署到谷歌云应用程序引擎,该引擎运行正常。然而,任何时候浏览器刷新的路径不是应用程序的根,我们得到的是404

这是我们的app.yaml文件:

runtime: nodejs8

handlers:
  - url: /
    static_files: dist/song/index.html
    upload: dist/song/index.html
    secure: always

  - url: /(.*)
    static_files: dist/song/\1
    upload: dist/song/(.*)
    secure: always

  - url: /dashboard
    static_files: dist/song/index.html
    upload: dist/song/index.html
    secure: always
错误是404,表示“未找到处理程序引用的静态文件:song/dashboard/all购物者”


因此,它在目录结构中寻找一个静态文件,但这是Angular应用程序中的一个路由。

您可能需要将每个请求重定向到index.html,让Angular路由器处理所有事情

- url: /.*
  secure: always
  redirect_http_response_code: 301
  static_files: dist/song/index.html
  upload: dist/song/index.html
  http_headers:
    Strict-Transport-Security: max-age=31536000; includeSubDomains
    X-Frame-Options: DENY

我也遇到了同样的问题,尝试了上面的答案,但没有成功。经过多次尝试和错误,我最终得到了下面的app.yaml。这一个适用于我的设置,使用Google Cloud Build直接部署到Google应用程序引擎

作为奖励,它还将HTTP请求重定向到HTTPS,并跳过通常不需要的文件

我相信可能有更有效的方法来做这件事,但一旦我开始工作,我就不敢再改变它了

app.yaml:

runtime: python27
api_version: 1
threadsafe: yes

handlers:
  - url: /(.+\.js)
    static_files: dist/project/\1
    upload: dist/project/(.+\.js)
    secure: always
    redirect_http_response_code: 301

  - url: /(.+\.css)
    static_files: dist/project/\1
    upload: dist/project/(.+\.css)
    secure: always
    redirect_http_response_code: 301

  - url: /(.+\.png)
    static_files: dist/project/\1
    upload: dist/project/(.+\.png)
    secure: always
    redirect_http_response_code: 301

  - url: /(.+\.jpg)
    static_files: dist/project/\1
    upload: dist/project/(.+\.jpg)
    secure: always
    redirect_http_response_code: 301

  - url: /(.+\.gif)
    static_files: dist/project/\1
    upload: dist/project/(.+\.gif)
    secure: always
    redirect_http_response_code: 301

  - url: /(.+\.svg)
    static_files: dist/project/\1
    upload: dist/project/(.+\.svg)
    secure: always
    redirect_http_response_code: 301

  - url: /favicon.ico
    static_files: dist/project/favicon.ico
    upload: dist/project/favicon.ico
    secure: always
    redirect_http_response_code: 301

  - url: /(.+\.json)
    static_files: dist/project/\1
    upload: dist/project/(.+\.json)
    secure: always
    redirect_http_response_code: 301

  - url: /(.+)
    static_files: dist/project/index.html
    upload: dist/project/index.html
    secure: always
    redirect_http_response_code: 301

  - url: /
    static_files: dist/project/index.html
    upload: dist/project/index.html
    secure: always
    redirect_http_response_code: 301

skip_files:
  - e2e/
  - node_modules/
  - src/
  - ^(.*/)?\..*$
  - ^(.*/)?.*\.md$
  - ^(.*/)?.*\.yaml$
  - ^LICENSE
服务:默认值
运行时:python27
api_版本:1
线程安全:正确
处理程序:
-网址:/*
静态文件:/index.html
上传:/index.html
-网址:/
静态目录:

只需使用url
/.*
添加一个通配符路由,以始终重定向到您的索引。html

您好,很抱歉这么晚才问您,但它对我不起作用。您能帮我吗please@DShultz你的app.yaml最终是什么样子的?我也有同样的问题。@Kenneth还是同一个yaml,但是,最终我们没有部署Angular应用程序,而是在本地运行ng build,然后将静态资产部署到云。(使用runtime:nodejs10 now)UPDATE:下面接受的答案是可行的,但是最终我们解决了问题,没有部署Angular应用程序,而是在本地运行ng build,然后将静态资产部署到云。(使用runtime:nodejs10 now)我尝试了上述方法,它对我有效,但唯一的问题是每次刷新时它都会从主页重定向。有没有解决办法,或者我有什么遗漏。
service: default
runtime: python27
api_version: 1
threadsafe: true
handlers:
  - url: /.*
    static_files: <your folder>/index.html
    upload: <your folder>/index.html
  - url: /
    static_dir: <your folder>