跳到主内容

在CDN中托管静态文件

Frontend assets (e.g. .js and .css) live in web/build/assets/ (web/build/static/ before v4). 通过Casdoor存储提供商将其上传至CDN;仓库中的脚本可自动完成此操作。

备注

先构建前端。请查看服务器安装说明,如有需要。

准备工作​

在 Casdoor UI 中创建存储提供商(例如阿里云 OSS)。

:::注意 将域字段设置为以/.

storage_domian :::

使用说明​

脚本位于deployment/deploy_test.go。在 GetProvider() 中设置提供商;ID 格式为 <owner>/<name>。

func TestDeployStaticFiles(t *testing.T) {
provider := object.GetProvider("admin/provider_storage_aliyun_oss")
deployStaticFiles(provider)
}

然后运行:

cd deployment
go test

成功后您应看到:

PASS
ok github.com/casdoor/casdoor/deployment 2.951s

工作原理​

脚本:

  1. Uploads the files under web/build/assets/ to the storage provider (your CDN).
  2. 把 web/build/index.html 中 .css 和 .js 的地址改写为指向 CDN。

像往常一样从Casdoor后端提供从Casdoor后端提供;浏览器将使用index.htmlindex.html。