我可以使用Angular 2创建基本的前端应用程序,并可以使用python在Google App引擎上创建带有端点的后端.然而,我似乎无法弄清楚如何将两者放在一起并使用云SDK部署它们.
这是一个基本的例子,我甚至无法在GAE上托管一个没有后端调用的简单angular2应用程序.在使用angular2 CLI构建之后,我已经使用了dist文件夹,并尝试使用app.yaml文件连接到该文件夹.它似乎在浏览器开发人员(dev_appserver.py app.yaml)中工作,虽然我在SDK中遇到404错误,我认为我的index.html文件有GET请求.然后我创建一个空白的index.yaml文件并尝试部署它,但在appspot.com位置获得404错误.这是app.yaml文件:
application:
version:
runtime: python27
threadsafe: true
api_version: 1
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: (.*)/
static_files: dist\1/index.html
upload: dist
- url: (.*)
static_files: dist\1
upload: dist
Run Code Online (Sandbox Code Playgroud)
我真的不知道我做错了什么.我是否需要某种main.application python后端来连接dist文件或?我是否需要在Angular2中包含节点模块或其他类型的文件?任何帮助都将受到大力赞赏!谢谢
这对我来说很难做到正确。通过Google进行指导的方式很少。我希望这对其他人有帮助。
正如Dan Cornilescu所指出的,管理人员接受第一场比赛。因此,我们从更具体到更具体。我已经按照以下步骤创建的文件夹结构解决了这个问题npm run build
:1.处理js,css和media的子目录。2.处理对manifest.json和fav.ico的json和ico请求。3.将所有其他流量路由到index.html。
handlers:
- url: /static/js/(.*)
static_files: build/static/js/\1
upload: build/static/js/(.*)
- url: /static/css/(.*)
static_files: build/static/css/\1
upload: build/static/css/(.*)
- url: /static/media/(.*)
static_files: build/static/media/\1
upload: build/static/media/(.*)
- url: /(.*\.(json|ico))$
static_files: build/\1
upload: build/.*\.(json|ico)$
- url: /
static_files: build/index.html
upload: build/index.html
- url: /.*
static_files: build/index.html
upload: build/index.html
Run Code Online (Sandbox Code Playgroud)
欢迎提供更有效的答案。
原始问题:
为反应路由器路由设置GAE app.yaml会产生“意外令牌<”错误。
在开发环境中,所有路径都可以在直接调用时起作用。localhost:5000和localhost:5000 / test产生预期的结果。
在GAE标准app.yaml中,当直接调用URL www.test-app.com时,该函数用于根目录。 www.test-app.com/test会产生404错误。
app.yaml #1
runtime: nodejs8
instance_class: F1
automatic_scaling:
max_instances: 1
handlers:
- url: /
static_files: build/index.html
upload: build/index.html
Run Code Online (Sandbox Code Playgroud)
对于所有路径,将app.yaml配置为接受通配符路由失败。www.test-app.com/和www.test-app.com/test产生错误“意外令牌<”。看来它正在将.js文件作为index.html提供。
app.yaml …
Run Code Online (Sandbox Code Playgroud) google-app-engine app.yaml google-cloud-platform react-router create-react-app
我在使用 python(3.5) 部署我的 django(2.1) 应用程序到 appengine 时遇到了这个错误。之前,我在 app.yaml 中使用 python 2 和 python27,没有这样的错误,但是现在当我的 app.yaml 中有 python 3.5.2 和 python37 时,我在“gcloud app deploy”之后遇到了这个错误。我真的必须启用计费功能还是我做错了什么?有出路吗?完整的错误是
错误:(gcloud.app.deploy) 错误响应:[7] 未配置访问权限。Cloud Build 之前未在项目 chaipani-217815 中使用过或已禁用。通过访问https://console.developers.google.com/apis/api/cloudbuild.googleapis.com/overview?project=chaipani-217815启用它,然后重试。如果您最近启用了此 API,请等待几分钟,让操作传播到我们的系统并重试。
django google-app-engine python-3.x app.yaml google-cloud-platform
我最近建立了一个新的Google Cloud Platform实例来托管我的WordPress网站.我目前在盒子上运行了大约4个站点,到目前为止一直运行良好(虽然有一个巨大的学习曲线!).
我基本上是在我的WordPress迁移结束时,但我现在遇到了永久链接的问题.设置页面中提供的WordPress自定义URL永久链接对我来说根本不起作用.当我将其更改为默认值以外的任何内容时,当我尝试导航到页面时,我得到404.
我在网上做了很多研究,发现这可能与.HTACCESS文件有关,并确保我有适当的设置.问题是GPC不使用.htaccess而是使用另一个名为app.yaml的文件.我一直无法在网上找到有关如何配置它以使用我的WordPress永久链接的任何内容!
有谁知道如何做到这一点?
提前致谢.
我是Google App Engine的初学者,也是Python的Web开发人员.在制作了一个基于Python的小应用程序后,我一直在尝试过去6天将其上传到GAE上.下面的"app.yaml"文件给出了之后给出的错误.
application: web2py
version: 1
runtime: python27
api_version: 1
threadsafe: false
default_expiration: "24h"
handlers:
- url: /(?P<a>.+?)/static/(?P<b>.+)
static_files: applications/\1/static/\2
upload: applications/(.+?)/static/(.+)
secure: optional
- url: /favicon.ico
static_files: applications/welcome/static/favicon.ico
upload: applications/welcome/static/favicon.ico
- url: /robots.txt
static_files: applications/welcome/static/robots.txt
upload: applications/welcome/static/robots.txt
- url: .*
# script: gaehandler.py # CGI
# script: web2py.app # ?
script: gaehandler.wsgiapp # WSGI (Python 2.7 only)
secure: optional
admin_console:
pages:
- name: Appstats
url: /_ah/stats
skip_files: |
^(.*/)?(
(app\.yaml)|
(app\.yml)|
(index\.yaml)|
(index\.yml)|
(#.*#)|
(.*~)|
(.*\.py[co])|
(.*/RCS/.*)| …
Run Code Online (Sandbox Code Playgroud) python google-app-engine yaml development-environment app.yaml
我正在使用app引擎提供一些静态js文件.我正在使用 gcloud preview app deploy .
这部署代码.
这当前部署了我的所有静态文件,是否有一种方法可以将我的静态目录中的单个js文件上传到app引擎?也许app.yaml配置?我基本上只需要scp file.js - > gcloud实例,但如果可能的话我想使用gcloud工具.
这是我的app.yaml:
version: 1
runtime: python27
api_version: 1
threadsafe: true
default_expiration: "30d"
- url: /(.*\.js)
mime_type: text/javascript
static_files: static/\1
upload: static/(.*\.js)
Run Code Online (Sandbox Code Playgroud) 我有一个 GAE 应用程序,它在 yaml 文件中的规则定义的静态文件下提供 DNS 中配置的两个不同域名,一个旧域名和一个新域名,但除此之外,它们为每个域名提供相同的内容。我想将请求从旧域重定向到新域。我已经看到了这个问题,但是我认为这失去了在 yaml 中使用静态资产处理程序的能力,并且必须在我的 main.py 中明确设置静态资产服务。当主机名是旧域时,是否有一种简单的方法(最好在 yaml 文件本身中)进行重定向,但为新域保留我的静态文件规则?
更新
这是我最终使用的完整解决方案:
### dispatch.yaml ###
dispatch:
- url: "*my.domain/*"
module: redirect-module
### redirector.yaml ###
module: redirect-module
runtime: python27
threadsafe: true
api_version: 1
skip_files:
- ^(?!redirector.py$)
handlers:
# Redirect everything via our redirector
- url: /.*
script: redirector.app
### redirector.py ###
import webapp2
def get_redirect_uri(handler, *args, **kwargs):
return 'https://my.domain/' + kwargs.get('path')
app = webapp2.WSGIApplication([
webapp2.Route('/<path:.*>', webapp2.RedirectHandler, defaults={'_uri': get_redirect_uri}),
], debug=False)
Run Code Online (Sandbox Code Playgroud)
一些额外的文档:https : //cloud.google.com/appengine/docs/python/modules/routing#routing_with_a_dispatch_file
我的目录中有一个 YAML 文件,我想使用 java 编程验证 YAML 文件的结构是否正确。在网上它有很多 YAML 检查器,但我想在 java 编程上验证它。
我的 中有以下处理程序部分app.yaml
:
handlers:
- url: /(robots\.txt|sitemap\.xml)
static_files: \1
upload: (robots\.txt|sitemap\.xml)
secure: always
http_headers:
Strict-Transport-Security: 'max-age=63072000; includeSubDomains; preload'
- url: /.*
script: main.app
secure: always
http_headers:
Strict-Transport-Security: 'max-age=63072000; includeSubDomains; preload'
Run Code Online (Sandbox Code Playgroud)
由另一个子模块 ( static.yaml
) 服务的另一个子域具有以下内容:
handlers:
- url: /
static_dir: files
secure: always
http_headers:
Access-Control-Allow-Origin: '*'
Strict-Transport-Security: 'max-age=63072000; preload'
Run Code Online (Sandbox Code Playgroud)
我能够static.yaml
在没有任何问题的情况下部署应用程序引擎:
$ appcfg.py update static.yaml
12:48 PM Host: appengine.google.com
12:48 PM Application: XXXXXX; module: static; version: 1
12:48 PM
Starting update of app: XXXXXXXX, module: static, version: 1 …
Run Code Online (Sandbox Code Playgroud) app.yaml ×10
yaml ×3
angular ×1
django ×1
gcloud ×1
hsts ×1
http-headers ×1
https ×1
java ×1
javascript ×1
parsing ×1
python ×1
python-3.x ×1
react-router ×1
redirect ×1
snakeyaml ×1
wordpress ×1