简体   繁体   English

Google App Engine,提供静态文件

[英]Google App Engine, serving static files

I want to create similar environments for development, testing and deployment - and I am currently in the process of porting my app from compute engine to app engine. 我想为开发,测试和部署创建类似的环境-目前正在将我的应用程序从计算引擎移植到应用程序引擎。

Currently I have express serving static files through the standard method: 目前,我已经通过标准方法来提供静态文件投放服务:

app.use(express.static('../dist'));
app.use(express.static('../public'));

Reading over the App Engine docs it is not very clear how to set this up correctly to work on localhost & web-preview they provide and finally in production. 通过阅读App Engine文档,目前尚不清楚如何正确设置此设置,以使其能够在他们提供的localhost和网络预览上使用,并最终在生产中使用。

Are the handlers within app.yaml necessary or can this be left to express? app.yaml的处理程序是必需的还是可以app.yaml表述?

Some extra clarification: 一些额外的澄清:

  • I want to avoid if/else based on environment 我想避免基于环境的if/else
  • I want a single method of serving static files, they should be accessible via a url, but also for express to send based on route logic. 我想要一种提供静态文件的方法,它们应该可以通过url访问,但也可以基于路由逻辑进行快速发送。

And I am using the flexible app engine environment. 我正在使用灵活的 App Engine环境。

Using the app.yaml handlers configuration for serving static files is specific to the standard environment only, see Serving Static Files . 使用app.yaml处理程序配置来提供静态文件仅适用于标准环境,请参阅《 提供静态文件》 Quite common confusion, this may help: How to tell if a Google App Engine documentation page applies to the standard or the flexible environment . 常见的混淆可能会有所帮助: 如何判断Google App Engine文档页面是适用于标准环境还是灵活环境

For the flexible environment the instructions are at Serving Static Files : 对于灵活的环境,说明位于“ 提供静态文件”

The flexible environment allows you to decide how to serve static content for your application. 灵活的环境使您可以决定如何为应用程序提供静态内容。 You can serve static content directly from your application, host it on a GCP option like Cloud Storage , or use a third-party content delivery network (CDN). 您可以直接从应用程序提供静态内容,也可以将其托管在GCP选项(如Cloud Storage)上 ,也可以使用第三方内容交付网络(CDN)。

Since you want to serve the static content from your application, your already implemented solution based on express.static (just as in Example of serving static files with your app ) should be all you need, for all environments. 由于您想从应用程序中提供静态内容,因此对于所有环境,您都已经需要基于express.static实现的解决方案(就像在使用应用程序提供静态文件的示例中一样 )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM