Hosting static files in a CDN
Frontend assets (e.g. .js and .css) live in web/build/static/. Upload them to a CDN via a Casdoor storage provider; a script in the repo automates this.
nota
Build the frontend first. See Server installation if needed.
Preparação
Create a storage provider in the Casdoor UI (e.g. Aliyun OSS).
cuidado
Set the Domain field to a URL ending with /.
Uso
The script is at deployment/deploy_test.go. Set the provider in GetProvider(); the ID format is <owner>/<name>.
func TestDeployStaticFiles(t *testing.T) {
provider := object.GetProvider("admin/provider_storage_aliyun_oss")
deployStaticFiles(provider)
}
Then run:
cd deployment
go test
On success you should see:
PASS
ok github.com/casdoor/casdoor/deployment 2.951s
Como funciona
The script:
- Uploads files under
css/andjs/to the storage provider (your CDN). - Rewrites
.cssand.jsURLs inweb/build/index.htmlto point to the CDN.
Serve index.html from the Casdoor backend as usual; the browser will load the static assets from the CDN using the URLs in index.html.