英文:
How do you configure a servlet filter in Google App Engine's app.yaml file?
问题
以下是您要的翻译内容:
我正在编写一个用于部署到Google App Engine的Kotlin应用程序。我正在使用Gradle插件来执行实际的GAE部署操作。一切都运行得很好;我已经成功将一个hello-world应用程序部署到了GAE。
然而,现在我需要添加一个过滤器,具体而言是com.googlecode.objectify.ObjectifyFilter
。但是,一旦我将这个过滤器添加到我的app.yaml文件中,应用程序将无法再部署。相反,它会给我一个错误,告诉我"filter"不是预期的属性。
这是我的app.yaml文件:
runtime: java11
handlers:
- url: /*
filter: com.googlecode.objectify.ObjectifyFilter
这是错误信息:
> 任务:webservice:appengineDeployAll 失败
错误:(gcloud.app.deploy) 解析文件时出错:[C:\Users\mathew\Documents\fooApp\webservice\build\staged-app\app.yaml]
对于类型为URLMap的对象,出现了意外的属性'filter'。
在"C:\Users\mathew\Documents\fooApp\webservice\build\staged-app\app.yaml"中,第4行,第11列
我做错了什么?如何在GAE应用程序中配置过滤器?
英文:
I am writing a Kotlin app to be deployed on Google App Engine. I am using a Gradle plugin to do the actual deploy to GAE. Everything had been working fine; I successfully deployed a hello-world application to GAE.
However, now I need to add a Filter, specifically the com.googlecode.objectify.ObjectifyFilter
. But once I add this filter to my app.yaml file, the app will no longer deploy. Instead, it gives me an error telling me that "filter" was not an expected attribute.
Here is my app.yaml file:
runtime: java11
handlers:
- url: /*
filter: com.googlecode.objectify.ObjectifyFilter
Here is the error:
> Task :webservice:appengineDeployAll FAILED
ERROR: (gcloud.app.deploy) An error occurred while parsing file: [C:\Users\mathew\Documents\fooApp\webservice\build\staged-app\app.yaml]
Unexpected attribute 'filter' for object of type URLMap.
in "C:\Users\mathew\Documents\fooApp\webservice\build\staged-app\app.yaml", line 4, column 11
What am I doing wrong? How do I configure a filter in a GAE app?
答案1
得分: 1
你必须在部署描述文件中指定 Filter 类。然后,您可以在该过滤器类中设置您的标头。您可以在此处找到有关App Engine中过滤器的更多详细信息。
需要注意的是,这些过滤器不适用于对css和js文件的静态资源请求。
英文:
You must specify the Filter class in your deployment descriptor file. Then you can set your headers inside that filter class. Here you can find more details about Filters in App Engine.
Something to keep in mind is that these filters do not work for static resources requests for your css and js.files.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论