首页 \ 问答 \ Google App Engine API +静态架构(Google App Engine API + static architecture)

Google App Engine API +静态架构(Google App Engine API + static architecture)

我正在尝试(构建)构建JS客户端+ NodeJS服务器应用程序以在Google Cloud AppEngine(以及可能的其他GCP资源)上托管它的最佳方法。 所以我在这里寻找建议/最佳实践。

我们有一个在非默认AppEngine服务上运行的API服务器,并且希望能够在同一个项目上运行多个(例如开发/暂存/生产版本)(如果可能)。

我们希望在此系统上托管/提供我们的静态客户端应用程序,因为我们希望使用相同的域来指向它。

在我们基于服务器的常规设置中,客户端应用程序在domain.com/上代理/提供,对API的请求在domain.com/v1/

我一直在研究不同的选项 - 在AppEngine上运行一个单独的静态站点,并使用dispatch.yaml尝试路由请求 - 这个选项似乎不适用于域前缀,只有通配符,例如

dispatch:
- url: "my-client-service-project.appspot.com/"
  service: my-client-service
- url: "my-client-service-project.appspot.com/v1/*"
  service: my-backend-service

不起作用,但是:

- url: "*/v1/*"
  service: my-backend-service

是的,我们不想要的,因为我们想要尽可能地运行devstagingproduction

我一直在看的另一个选项是将静态文件夹作为我的应用程序的一部分托管,但我似乎无法使其工作,这里是我的app.yaml的片段:

handlers:
  - url: /.*
    static_files: client/dist/index.html
    upload: frontend/dist/index.html
  - url: /v1/*
    script: dist/index.js

我的猜测是script可能与Python应用程序的工作方式不同,但我可能错了 - 文档不是很清楚。

理想情况下,我想在存储上托管客户端前端静态文件并指向AppEngine API服务器(没有专门指向客户端的域,例如/v1/auth/login而不是my-backend-service-project.appspot.com/v1/

参考文献:

如何在google flex / app引擎环境中使用存储桶存储来提供静态文件?

由Google App Engine提供的Node.js +静态内容

https://cloud.google.com/appengine/docs/flexible/nodejs/serving-static-files

https://cloud.google.com/appengine/docs/standard/python/how-requests-are-routed#routing_via_url

https://cloud.google.com/appengine/docs/standard/python/config/appref

https://cloud.google.com/appengine/docs/standard/python/config/dispatchref


I'm trying to (con)figure the best way to structure a JS client + NodeJS server app to host it on Google Cloud AppEngine (plus possibly other GCP resources). So I'm looking for advice / best practices here.

We have an API server running on a non-default AppEngine service and would like to be able to run several, e.g. development/staging/production versions on the same project (if possible).

We would like to host / serve our static client app on this system because we want to use the same domain to point at it.

In our normal server based setup, the client app is proxied/served on domain.com/ and requests to the API are on domain.com/v1/

I've been working through different options - hosting a separate static site running on AppEngine and using dispatch.yaml to try to route requests - this option doesn't seem to work with domain prefixes, only wildcards, e.g.

dispatch:
- url: "my-client-service-project.appspot.com/"
  service: my-client-service
- url: "my-client-service-project.appspot.com/v1/*"
  service: my-backend-service

Doesn't work, but:

- url: "*/v1/*"
  service: my-backend-service

Does, which we didn't want because we'd like to run dev, staging & production if possible.

The other option I've been looking at is having the static folder hosted as part of my app, but I can't seem to get this working either, here is the snippet from my app.yaml:

handlers:
  - url: /.*
    static_files: client/dist/index.html
    upload: frontend/dist/index.html
  - url: /v1/*
    script: dist/index.js

My guess is that script may not work the same as for Python apps, but I could be wrong - the doc's aren't very clear.

Ideally, I'd like to host the client front-end static files on storage and point to the AppEngine API server (without specifically pointing to a domain from the client, e.g. /v1/auth/login rather than my-backend-service-project.appspot.com/v1/

References:

How can I use bucket storage to serve static files on google flex/app engine environment?

Node.js + static content served by Google App Engine

https://cloud.google.com/appengine/docs/flexible/nodejs/serving-static-files

https://cloud.google.com/appengine/docs/standard/python/how-requests-are-routed#routing_via_url

https://cloud.google.com/appengine/docs/standard/python/config/appref

https://cloud.google.com/appengine/docs/standard/python/config/dispatchref


原文:https://stackoverflow.com/questions/48705676
更新时间:2022-02-27 06:02

最满意答案

您是否只是想将InputStream的内容复制到字节数组中?

您可以使用将InputStream#read调用到字节数组的循环直接执行此操作,也可以使用Apache commons中的IOUtils.toByteArray将实现保留给其他人。

编辑 - 如果使用Apache commons方法,则无需处理数组初始化:

byte[] bytes = null;
try {
    bytes = IOUtils.toByteArray(conn.getInputStream());
} catch (IOException e) {
    // handle the exception
}

toByteArray使用ByteArrayOutputStream来避免toByteArray分配数组,但您不必担心这一点。


Are you trying to simply copy the content of an InputStream into a byte array?

You can do this directly with a loop that calls InputStream#read into a byte array, or you can leave the implementation up to others by using IOUtils.toByteArray from Apache commons.

Edit - You don't need to deal with array initialization if you use the Apache commons method:

byte[] bytes = null;
try {
    bytes = IOUtils.toByteArray(conn.getInputStream());
} catch (IOException e) {
    // handle the exception
}

toByteArray uses a ByteArrayOutputStream to avoid allocating an array up-front, but you wouldn't need to worry about this.

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。