如何将flask-socketio 应用程序部署到Google Cloud Platform App Engine

贡德·德特莱夫森

我编写了一个flask-socketio 应用程序,它通过websockets 向网站提供数据。

我的目录结构是这样的:

  • 主文件
  • 网站
    • 索引.html
    • 主文件
    • 样式文件

我的 app.yaml 是这样的:

runtime: python38

handlers:
  - url: /
    static_files: website/index.html
    upload: website/index.html

  - url: /
    static_dir: website

entrypoint: python main.py

我在目录中运行 gcloud app deploy 并设法将网站部署到 GCP。现在可以在https://codevis.ew.r.appspot.com/ 下使用

但是,flask-socketio 应用程序没有运行,我无法通过网站连接到它。

我的 main.py 像这样部署了 Flask-socketio 应用程序:

app = Flask(__name__)
socketio = SocketIO(app, cors_allowed_origins="*")

[...]

def run_app():
    socketio.run(app, debug=True)


if __name__ == "__main__":
    run_app()

在我的 main.js 中,我试图像这样连接到flask-socketio:

var socket = io.connect("https://codevis.ew.r.appspot.com:5000");

在本地测试 flask-socketio 时(使用 var socket = io.connect("http://127.0.0.1:5000");),一切正常。我只是无法让 GCP App Engine 实际运行 flask-socketio 应用程序。我究竟做错了什么?

纪尧姆·布拉基埃

App 引擎标准不支持 websockets。您可以在App Engine Flexible上执行此操作,但不能缩放到 0(这意味着额外的成本)

对于规模到 0 的平台,您可以考虑 Cloud Run,它很快将能够接受定向 websocket。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

将 Nuxt JS SSR 应用程序部署到 Google Cloud App Engine Standard

将Django应用程序部署到Google App Engine

将节点应用程序部署到Google App Engine

将ASP.NET Core 2.1应用程序部署到Google Cloud App Engine错误:字符范围错误

如何将SpringBoot应用程序部署到Google App Engine?

将Flask应用程序部署到Google Cloud Platform时无法获得正确的TensorFlow版本

Google Cloud App Engine Flex Env上的Flask-Socketio服务器

将C ++应用程序部署到Google Cloud Platform Kubernetes引擎

如何将Google Cloud App Engine Web应用程序链接到Google Compute Engine VM实例?

如何将新服务部署到Google App Engine中的现有应用程序?

无法将Java应用程序部署到App Engine

将 Node 应用程序部署到 Google Cloud App Service - 如何编辑我的代码?

如何将Flask应用作为程序包部署到App Engine?

将基本的Angular 2应用程序部署到Google App Engine

将应用程序部署到Google App Engine,并希望启动api和客户端

如何将一个App Engine应用程序部署到多个项目

将Python Flask应用程序部署到Google App Engine时,没有名为“ flask”的模块

如何将 Django PostgreSQL 数据库部署到 Google Cloud SQL (App Engine)

如何通过Google App Engine中的应用程序将文件写入Google Cloud Storage?

将应用程序移植到Google App Engine

在Google Cloud App Engine上部署闪亮的应用程序会返回错误

当我尝试将PHP应用程序部署到Google App Engine时,为什么突然出现400错误?

将 Symfony 4 应用程序部署到 Google App Engine 时出现安全检查器错误

如何在 Google Cloud Platform 上的 App Engine 中更改 php 版本(运行时)?

如何从Google App Engine应用程序发送Firebase Cloud消息

如何保护App Engine应用程序仅对Google Cloud Task可用?

Google Cloud中的不同App Engine应用程序

从部署在Google Cloud App Engine中的Node JS应用程序查询时,Cloud SQL抛出ETIMEDOUT错误

如何从 App Engine 中的 Cloud Shell 部署 GCS 中我的应用程序存储桶中的文件?