For AI agents: the complete documentation index is available at https://docs.clickmax.io/en/llms.txt, the full documentation bundle is available at https://docs.clickmax.io/en/llms-full.txt, and this page is available as Markdown at https://docs.clickmax.io/en/features/create/max-design/server-routes.md.
  • English
  • How do I run server code in a Max Design site?

    Ask Max, in the project's conversation, for a server route: an address of the site, always under /api, that runs code outside the visitor's browser. The key that code uses is stored as a project secret, outside the code and the conversation. After testing in the preview, publish the site: the route answers on the site's own address, for example https://my-site.clickmax.space/api/quote.

    Prerequisites: a Max Design project (see How to create a site or a page with Max), permission to edit in Max Design and, to save or delete secrets, the Manage action on Max Design in your role (see Who can change secrets). The feature is being enabled account by account: if Max says it cannot create server routes in your project, it has not reached your account yet.

    When to use a server route

    Use one when the page needs something that cannot live in the visitor's browser:

    • Calling another service's API with a secret key. Anything sent to the browser can be read by whoever visits the site; the server route makes the call and returns only the result.
    • Receiving a webhook from another service, such as a payment or sign-up notification.
    • Running a calculation or a validation the visitor should not see or change.

    Clickmax capture forms, triggers and checkout do not need a server route: ask Max as usual.

    Ask Max for the route

    1. In the project's conversation, say what the route should do and which service it calls. For example: "create a route that looks up shipping in the carrier's API and shows the price on the sales page".
    2. If the route needs a key, Max asks for the secret in the conversation itself, in a password field, already carrying the name the code will use. Paste the value into Secret value and click Save. You can also click Skip and save it later in the project settings.
    3. Max writes the route's code and connects the page to it.

    The value you type in that field goes straight to the project's vault. Max only learns whether you saved or skipped: the value does not enter the conversation or the code.

    Never paste a key into a chat message or ask Max to write it into a file. Whatever is in the project's code can end up on the published site.

    In projects created before this feature, Max tells you the project must be updated before it can have server routes.

    Store a secret in the project settings

    1. Click Config, at the top of the preview, to open the Project settings.
    2. In the side menu, under Publishing, click Secrets.
    3. Under Save a secret, fill in Name and Value and click Save secret.

    Rules for the name and the value:

    • The name uses uppercase letters, digits and _, starts with a letter and has up to 64 characters, such as SHIPPING_API_KEY. It cannot start with CLICKMAX_.
    • The value has up to 8,192 characters.
    • Each project stores up to 50 secrets.

    Once saved, the value is never shown again: the list shows only the name and the creation and change dates. To rotate a key, click Replace value on the secret's row, fill in the new Value and click Save secret. To remove it, click the trash icon on the row and confirm with Delete secret.

    Saving, replacing or deleting a secret applies to the published site without publishing again. The change can take about a minute to reach the live site. If you delete a secret the code still uses, the route starts failing: ask Max to adjust the code first.

    If the notice "Secret saved, but it has not reached the published site yet" appears, click Save secret again with the same value.

    Secrets belong to the project: they apply to the preview and to the published site, and another project in the same workspace cannot see them.

    Test in the preview

    The preview runs the project's server routes with the saved secrets, so the test uses the real key.

    1. Open the page that uses the route in the preview and do the action that calls it, such as submitting the form or clicking the button.
    2. If the result does not come, tell Max what happened. Max calls the route, reads its logs (the code's messages and errors) and fixes it.

    You can also ask for the test directly: "test the shipping route with ZIP code 01310-100". Max shows the response it got.

    Because the preview uses the real secrets, a route that creates an order or sends a message in the other service does so during the test too. While testing, prefer a test key from the service and replace the value before sharing the site.

    Publish

    Click Publish, as with any change to the site (see Publish the page). Routes go live together with the pages, on the site's own address, under /api. On a site published at www.yourdomain.com, the route /api/shipping answers at https://www.yourdomain.com/api/shipping.

    To receive a webhook, publish first and then register the route's address in the other service. The preview address is for testing and changes.

    The published route is public, like the rest of the site: anyone with the address can call it. For a webhook, ask Max to check the signature the other service sends, using a secret.

    If the site is on a domain of yours, server routes only answer on domains on the new version of domains. On a domain still connected through the previous version, pages open but routes do not. See How do I migrate my domain to the new version without taking the site down?.

    Limits and restrictions

    • Address: routes always live under /api. The rest of the site is still made of pages prepared at publish time.
    • Site at the root of the address: routes only publish on a site that answers at the root of its address, such as www.yourdomain.com. A site published under a path, such as www.yourdomain.com/promo, cannot have server routes: publishing fails until the routes are removed or the site moves to the root.
    • Execution time: each call gets up to 100 milliseconds of processing. Time spent waiting for another service's response does not count. The code should answer quickly, with no long tasks.
    • Outgoing calls: each call to the route can make up to 20 calls to other services.
    • Allowed destinations: only public https:// addresses on the default port. Calls over http://, to an IP number, to internal network names (such as localhost), to the site itself or to Clickmax addresses are refused. The exception is the Clickmax API and the OAuth login of Clickmax Apps: the route can request a Clickmax App's tokens, including the session token exchange, and call the API, as a Clickmax App built in Max Design needs. On calls to the Clickmax API, the per-origin limit counts per project, not per the routes' shared IP. Redirects are not followed automatically.
    • Size: the route receives up to 1 MB per call and returns up to 10 MB.
    • Volume: each visitor can make up to 300 calls every 10 seconds and 1,200 per minute to the routes of one site. Above that, the route answers with error 429 until the pace drops.
    • Not available yet: a database or storage of the site's own, scheduled tasks, queues and WebSocket. To store data, the route can call a service of yours.

    Clickmax App built in Max Design

    Max can build a site that opens inside the Clickmax panel, under Apps, and calls the API on behalf of whoever uses it. Publishing creates the app and its credentials for you: nobody needs to create the app in My apps or copy an ID or secret.

    1. Ask Max for the app, or turn it on in Config > Clickmax App > Open inside Clickmax. The project gets the .clickmax/app.json file, with the app's name and requested permissions, plus the files that talk to the panel and exchange the token.
    2. Ask Max what the app should show or do. It adjusts the permissions in .clickmax/app.json to what the routes need.
    3. Publish. On the first publish, and whenever the app starts asking for a new permission, Clickmax shows the permissions for you to confirm. Only someone who manages apps can confirm.
    4. Open the app under Apps in the panel. To test the preview before publishing again, use Open preview in Clickmax in the preview bar.

    Publishing creates a Private app, installed only in this workspace, at the site's published address. The credentials live in the project's Secrets (APP_CLIENT_ID and APP_CLIENT_SECRET), saved by Clickmax. Taking the site offline suspends the app, and the next publish reactivates it. If the app asks for fewer permissions, the installation loses the removed ones on the next publish.

    Even when the app has a permission, each person can only do what their role allows. To see the live app's errors, ask Max to read the published site's logs.

    The contract details, to check what Max wrote, are in Apps inside Clickmax.

    If the route does not answer

    When Clickmax itself refuses or cannot run the call, the response comes as JSON with an error code:

    • 413: the call sent more than 1 MB. Send less data per call.
    • 429: too many calls in a short time. Wait and try again. If it persists under light traffic, contact support.
    • 500 with the code worker_error: the route's code failed or went over a limit. Ask Max to read the route's logs in the preview and fix it, then publish again.
    • 502 or 503 with the code worker_unavailable: the route could not be loaded or is temporarily unavailable. Try again in a few seconds. If it persists, publish the site again, then contact support.
    • 503 with the code worker_disabled: the site's routes were disabled by Clickmax. Contact support.

    Other responses come from the route's code: ask Max to explain or fix them.

    Who can change secrets

    Secrets have their own action in permissions, because a key applies to the whole published site:

    • View on Max Design shows the secret names, never the values.
    • Manage on Max Design allows saving, replacing and deleting secrets, both in the project settings and in the field Max opens in the conversation.
    • Edit on Max Design still covers asking Max for the route and publishing.

    Someone with Edit but without Manage can ask for the route and publish, but needs another person to save the secret. Administrators have full access. To adjust a role, see Permissions.