Skip to content

Cloudflare Workers Backend

  1. Click Workers & Pages -> Overview -> Create Application

    worker1

  2. Select Worker, click Create Worker, change the name, and then click Deploy

    worker2

  3. Download worker.js

  4. After the Deploy is successful, the following interface will appear. Click Edit Code, delete the original file, upload worker.js, and click Deploy.

    Note
    You need to click the Explorer in the left menu first.
    In the file list window, right-click and find Upload in the context menu.
    Please refer to the screenshot below.

    worker3

    worker4

  5. Click Settings -> Domains & Routes. Here you can add your own domain, or you can use the automatically generated *.workers.dev domain. Remember this domain, as you will need it when deploying the frontend.

    Note
    Open the worker's url/test. If it displays {"code":200,"message":"Test route is working!"}, it means the deployment is successful.

    worker5

  6. Click Settings -> Variables and Secrets, and add variables as shown in the image.

    Note
    If you have a moderatecontent review apikey, you can add variables to enable the review feature.
    Add the variable name ModerateContentApiKey with the value being the key or token from moderatecontent.
    It seems the login entrance on the moderatecontent official website is currently unavailable.

    worker6

    【v0.0.5】New variable: INCLUDE_PRIVATE_IN_RANDOM value is true, the random image includes private images; value is false, it is a public image, i.e. an image uploaded by a non-logged-in user

  7. Click Settings -> Bindings, click Add, name it as shown in the image, select the D1 database you just created, and click Deploy.

    worker7

  8. Click Settings -> Bindings, click Add, name it as shown in the image, select the KV namespace you just created, and click Deploy.

    worker8

Released under the MIT License