Summary#
This tutorial is not a serverless deployment of AList, but rather deploys the front-end page to Cloudflare Pages, allowing users to quickly pull front-end files from Cloudflare's edge nodes without going back to the origin, improving the browsing experience. The back-end still requires a server exposed to the public network to deploy AList (if there is no public server, Cloudflare Tunnels can be used).
First, ensure your back-end server supports dual-stack access (IPv4 and IPv6)#
-
Use Cloudflare Tunnel to tunnel through Cloudflare.
-
Set up A and AAAA records separately; it's troublesome. If your IP is fast, you might not need to separate the front and back ends. Exposing the origin's front and back ends cannot avoid DDoS attacks because your origin will be exposed in the HTTP message.
Then, officially deploy the AList front-end to Cloudflare Pages#
- Fork the repository:
- Change the
env.production
file in the project root directory to your back-end server address
- Clone the repository to your local machine; you need to install Git:
Using SSH (you need to hold your Github SSH private key):
git clone git@github.com:your_username/your_forked_repository
Using HTTPS (there's a chance of SSL handshake failure in China):
git clone git@github.com:your_username/your_forked_repository
-
Download the localization package: AcoFork's cloud storage or Crowdin - login required
-
Unzip it, and copy the
Zh-CN
folder fromalist (zh-CN)\src\lang
tosrc/lang
under the repository. -
Edit the
.gitignore
in the root directory, adding a line!/src/lang/zh-CN/
to ensure the files are not ignored. -
Download Node.js. Open a terminal in the root directory to generate the files needed for Chinese:
Install cnpm:
npm install -g cnpm --registry=https://registry.npmmirror.com
Install dependencies:
cnpm install --legacy-peer-deps
Generate files needed for Chinese:
node .\scripts\i18n.mjs
- Stage the changes and commit to the remote repository; open a terminal in the root directory.
git add . //Stage the changes
git commit -m Add Chinese //Commit the changes
git push -f //Force push the changes to the remote repository
- Go to the Cloudflare Dashboard, and navigate to the Workers and Pages page
- Create a Pages, and choose to connect to a Git repository
- Select your repository and start the setup
- Enter the build command:
pnpm install && pnpm build
, and choose the build output directory as/dist
- Wait for Cloudflare to finish building, and bind a custom domain to Pages
- Visit the custom domain to check if AList is functioning properly
Customizing AList#
We all know that AList supports custom headers and content, but since Cloudflare Pages is a static page, we adopt a hard-coded method to directly write the content that needs to be customized into the
index.html
in the root directory.
- Edit the
index.html
in the root directory. - Stage the changes and commit to the remote repository; open a terminal in the root directory.
git add . //Stage the changes
git commit -m Your commit summary //Commit the changes
git push -f //Force push the changes to the remote repository
- Cloudflare Pages will automatically rebuild; wait for the new webpage to finish building.