简体   繁体   中英

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.

Are the handlers within app.yaml necessary or can this be left to express?

Some extra clarification:

  • I want to avoid if/else based on environment
  • 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.

And I am using the flexible app engine environment.

Using the app.yaml handlers configuration for serving static files is specific to the standard environment only, see Serving Static Files . Quite common confusion, this may help: How to tell if a Google App Engine documentation page applies to the standard or the flexible environment .

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).

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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