在 Deta Space 部署 Vue + Python

Deta is building a personal computer on the internet — “a personal cloud” — called Deta Space. If you build software for the internet, Space wants to make it dramatically easier to do so. If you’re a user of the internet, Space wants to bring the freedom of personal computing to your life online.

本文讨论如何在其上部署一个 Vue 为前端 + Python 为后端的服务。

目录结构

some_project
├── Spacefile
├── backend
│   ├── main.py
│   ├── requirements.txt
│   └── ...
└── frontend
    ├── dist
    ├── index.html
    ├── node_modules
    ├── package-lock.json
    ├── package.json
    ├── public
    ├── src
    ├── vite.config.js
    └── ...

Spacefile

# Spacefile Docs: https://go.deta.dev/docs/spacefile/v0
v: 0
micros:
  - name: frontend
    src: frontend
    engine: vue
    primary: true
    path: app
    public: true
    serve: dist/
  - name: backend
    src: backend
    engine: python3.9
    public: true
    path: api
    dev: gunicorn main:app

P.S.: 2023.06 发现的小问题是如果 Python 的依赖没有装全,后端服务会502,但 Runtime Log 中并不能看到报错。

按照如上的方式配置好Spacefile后,便可以直接根据通过path来将请求相应地路由到前/后端。在这个例子中,我们如果想要在前端的 Javascript 代码中访问后端接口,只需:

fetch(`/api/xxx`);

即可。

Refrence:

Contents


本作品采用知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议进行许可。

知识共享许可协议