Skip to content

Cloudflare Workers Backend

Note

The worker.dev domain is not accessible in China, please use a custom domain.

  1. Click Compute (Workers) -> Workers & Pages -> Create

    create worker

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

    worker1worker2

  3. Go back to Workers & Pages, find the worker you just created, click Settings -> Runtime, modify Compatibility flags, manually add nodejs_compat, and the compatibility date also needs to be later than the date shown in the image.

    worker-runtime

  4. Download worker.js

  5. Go back to Overview, find the worker you just created, click Edit Code, delete the original file, upload worker.js, and click Deploy

    NOTE

    To upload, first click Explorer in the left menu, then right-click in the file list window and find Upload in the context menu, please refer to the screenshots below

    Reference: issues156

    worker3

    worker-upload

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

    worker-var

    Note

    For more variable configuration, please see Worker Variables Documentation

    Note that the outermost quotes are not needed for string format variables

    For USER_ROLES, please configure in this format: [{"domains":["awsl.uk","dreamhunter2333.xyz"],"role":"vip","prefix":"vip"},{"domains":["awsl.uk","dreamhunter2333.xyz"],"role":"admin","prefix":""}]

    Recommended variable list

    Variable NameTypeDescriptionExample
    PREFIXTextDefault prefix for new email names, can be omitted if no prefix neededtmp
    DOMAINSJSONAll domains for temporary email, supports multiple domains["awsl.uk", "dreamhunter2333.xyz"]
    JWT_SECRETText/SecretSecret for generating JWT, JWT is used for login and authenticationxxx
    ADMIN_PASSWORDSJSONAdmin console password, console access not allowed if not configured["123", "456"]
    ENABLE_USER_CREATE_EMAILText/JSONWhether to allow users to create emails, not allowed if not configuredtrue
    ENABLE_USER_DELETE_EMAILText/JSONWhether to allow users to delete emails, not allowed if not configuredtrue
  7. Click Settings -> Bindings, click Add Binding, enter the name as shown, select the D1 database you just created, and click Add Binding

    Important

    Note that the binding name for D1 Database here must be DB

    worker-bindings

    worker-d1-1

    worker-d1-2

  8. Click Settings -> Triggers, here you can add your own domain, or you can use the automatically generated *.workers.dev domain. Record this domain, as it will be needed when deploying the frontend later.

    NOTE

    Open the worker url, if it displays OK, the deployment is successful

    Open /health_check, if it displays OK, the deployment is successful

    worker3

  9. If you want to enable the user registration feature and need to send email verification, you need to create a KV cache. You can skip this step if not needed.

    Important

    If you want to enable the user registration feature and need to send email verification, you need to create a KV cache. You can skip this step if not needed.

    Note that the binding name for KV here must be KV

    Click Storage & Databases -> KV -> Create Namespace, as shown in the image, click Create Namespace

    worker-kv

    worker-kv-0

    Then click Settings -> Bindings, click Add Binding, enter the name as shown, select the KV you just created, and click Add Binding

    worker-bindings

    worker-kv-1

    worker-kv-2

  10. Telegram Bot Configuration

    NOTE

    If you don't need Telegram Bot, you can skip this step

    Please first create a Telegram Bot, then get the token, add the token to Variables and Secrets, variable name: TELEGRAM_BOT_TOKEN

  11. If you want to use the scheduled task to clean emails in the admin page, you need to add a scheduled task in Settings -> Trigger Events -> Cron Triggers.

    NOTE

    Select cron expression, enter 0 0 * * * (this expression means run daily at midnight), click Add to add. Please adjust this expression according to your needs.

Based on MIT license