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
是的,我们不想要的,因为我们想要尽可能地运行dev , staging和production 。
我一直在看的另一个选项是将静态文件夹作为我的应用程序的一部分托管,但我似乎无法使其工作,这里是我的
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 ondomain.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 thanmy-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
最满意答案
您是否只是想将
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 aByteArrayOutputStream
to avoid allocating an array up-front, but you wouldn't need to worry about this.
相关问答
更多-
TCP/IP模型是一个________。[2023-05-19]
a -
你应该可以做这样的事情: byte[] bitmap = GetYourImage(); using(Image image = Image.FromStream(new MemoryStream(bitmap))) { image.Save("output.jpg", ImageFormat.Jpeg); // Or Png } 在这里寻找更多的信息。 希望这有助于。 You should be able to do something like this: byte[] bitmap = ...
-
在您的代码中,您永远不会等待BitmapImage从Web加载图像,因此当您访问它们时它不知道它的PixelWidth / PixelHeight。 您可以等待它加载 - 例如通过调用“await bi.WaitForLoadedAsync () ”使用AsyncUI库。 如果您想要访问解码像素,这对您来说不会真正有用,因为BitmapImage不允许您访问像素,并且目前没有API将BitmapImage转换为WriteableBitmap。 您可以查看有关该主题的早期问题 。 您需要使用类似HttpCli ...
-
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
我不是直接比较字节数组,而是比较图像的散列。 也许可以将以下内容提取到比较方法中: SHA256Managed sha = new SHA256Managed(); byte[] imgHash1 = sha.ComputeHash(imgBytes1); byte[] imgHash2 = sha.ComputeHash(imgBytes2); // compare the hashes for (int i = 0; i < imgHash1.Length && i < imgHash2.Length ...
-
关键要素是: File f = new File("pathToFile"); FileInputStream fis = new FileInputStream(f); byte[] bytes = new byte[f.length()]; fis.read(bytes); 当然还有异常处理等等,但这应该足以给你一般的想法。 The key elements are: File f = new File("pathToFile"); FileInputStream fis = new FileInpu ...
-
来自数据事件请求的数据是完美的,所以我使用了写流。 不知何故,收集所有数据搞砸了信息。 码: //server handling route if(QD === "/postImage"){ processPost(request, response, filename); } var processPost = function(request, response, name) { if(request.method == 'POST') { //repsonse obj ...
-
使用BitmapFactory.decodeByteArray()获取一个Bitmap ,然后使用该Bitmap创建一个Canvas ,并在那里绘制文本。 最后使用Bitmap.compress()保存它: Bitmap bmp = BitmapFactory.decodeByteArray(myArray, 0, myArray.length).copy(Bitmap.Config.RGBA_8888, true); //myArray is the byteArray containing the im ...
-
从Web下载jpg图像,将其保存到RAM上的字节数组中(Download a jpg image from the web saving it into a byte array on RAM)[2023-06-08]
您是否只是想将InputStream的内容复制到字节数组中? 您可以使用将InputStream#read调用到字节数组的循环直接执行此操作,也可以使用Apache commons中的IOUtils.toByteArray将实现保留给其他人。 编辑 - 如果使用Apache commons方法,则无需处理数组初始化: byte[] bytes = null; try { bytes = IOUtils.toByteArray(conn.getInputStream()); } catch (IOEx ... -
在php中使用ImageMagick的最简单方法是使用ImageMagick扩展和类。 我不建议使用exec函数。 首先,转换图像并将其存储在变量中。 你说你不习惯变量,但你的代码似乎就是你,你可能只是不知道它。 例如,您的$output是一个变量。 变量包含输出后的图像(如果成功)。 现在,我不是100%确定你的图层数组包含什么,如果它的图像或图像的路径,但我期望它的路径,所以我将采用这个假设。 你的第一个exec调用是一个转换,我不认为这是nessesery,因为你没有输入,所有你需要的是我所能看到的“ ...