|
2 | 2 |
|
3 | 3 | Cap Standalone is a self-hosted version of Cap's backend that allows you to spin up a server to validate and create challenges so you can use it with languages other than JS. |
4 | 4 |
|
5 | | -It's simple yet amazingly powerful, allowing you to use Cap in any language that can make HTTP requests. It's mostly compatible with reCAPTCHA and hCaptcha's siteverify enpoints, so you can use it as a drop-in replacement for them. |
| 5 | +It's simple yet powerful, allowing you to use Cap in any language that can make HTTP requests. It's mostly compatible with reCAPTCHA and hCaptcha's siteverify enpoints, so you can use it as a drop-in replacement for them. |
6 | 6 |
|
7 | | -It also offers API key support, a built-in assets server, a dashboard with statistics, and more. To get started, follow [the instructions to install it on your server](installation.md). |
| 7 | +It also offers API key support, a built-in assets server, a dashboard with statistics, and more. |
8 | 8 |
|
9 | 9 |  |
| 10 | + |
| 11 | +## Installation |
| 12 | + |
| 13 | +### Requirements |
| 14 | + |
| 15 | +You'll need to have [Docker Engine 20.10 or higher](https://docs.docker.com/get-docker/) installed on your server. Both `x86_64` (amd64) and `arm64` architectures are supported. |
| 16 | + |
| 17 | +--- |
| 18 | + |
| 19 | +Run the following command to pull the Cap Standalone Docker image from Docker Hub: |
| 20 | + |
| 21 | +```bash |
| 22 | +docker pull tiago2/cap:latest |
| 23 | +``` |
| 24 | + |
| 25 | +Then, to run the server, use the following command: |
| 26 | + |
| 27 | +```bash |
| 28 | +docker run -d \ |
| 29 | + -p 3000:3000 \ |
| 30 | + -v cap-data:/usr/src/app/.data \ |
| 31 | + -e ADMIN_KEY=your_secret_password \ |
| 32 | + --name cap-standalone \ |
| 33 | + tiago2/cap:latest |
| 34 | +``` |
| 35 | + |
| 36 | +Make sure to replace `your_secret_password` with a strong password, as anyone with it will be able to log into the dashboard and create keys. It'll need to be at least 30 characters long. |
| 37 | + |
| 38 | +Then, you can access the dashboard at `http://localhost:3000`, log in, and create a key. You'll get a site key and a secret key which you'll be able to use on your widget. |
| 39 | + |
| 40 | +On Debian and other OSes that don't use `iptables`, if you can't open the dashboard, try setting `--network=host` in the run command. Thanks to [Boro Vukovic](https://github.com/tiagozip/cap/issues/70#issuecomment-3086464282) for letting me know about this. |
| 41 | + |
| 42 | +You'll also need to make the server publicly accessible from the internet, as the widget needs to be able to reach it. If you're using a reverse proxy, make sure to check [the options guide](/guide/standalone/options.md) to configure rate-limiting properly. |
| 43 | + |
| 44 | +## Usage |
| 45 | + |
| 46 | +### Client-side |
| 47 | + |
| 48 | +Let's configure your widget to use your self-hosted Cap Standalone server. To do this, set the widget's API endpoint option to: |
| 49 | + |
| 50 | +``` |
| 51 | +https://<instance_url>/<site_key>/ |
| 52 | +``` |
| 53 | + |
| 54 | +Make sure to replace: |
| 55 | + |
| 56 | +- `<instance_url>`: The actual URL where your Cap Standalone instance is running. This URL must be publicly accessible from the internet. |
| 57 | +- `<site_key>`: Your site key from this dashboard. |
| 58 | + |
| 59 | +Example: |
| 60 | + |
| 61 | +```html |
| 62 | +<cap-widget |
| 63 | + data-cap-api-endpoint="https://cap.example.com/d9256640cb53/" |
| 64 | +></cap-widget> |
| 65 | +``` |
| 66 | + |
| 67 | +### Server-side |
| 68 | + |
| 69 | +After a user completes the CAPTCHA on your site, your backend needs to verify their token using this server's API. |
| 70 | + |
| 71 | +You can do this by sending a `POST` request from your server to the following endpoint: |
| 72 | + |
| 73 | +``` |
| 74 | +https://<instance_url>/<site_key>/siteverify |
| 75 | +``` |
| 76 | + |
| 77 | +Your request needs to include the following data: |
| 78 | + |
| 79 | +- `secret`: Your key secret from this dashboard. This is **not** the admin key, but rather your site key's secret. |
| 80 | + |
| 81 | +- `response`: The CAPTCHA token generated by the widget on the client-side |
| 82 | + |
| 83 | +Example using `curl`: |
| 84 | + |
| 85 | +```bash |
| 86 | +curl "https://<instance_url>/<site_key>/siteverify" \ |
| 87 | + -X POST \ |
| 88 | + -H "Content-Type: application/json" \ |
| 89 | + -d '{ "secret": "<key_secret>", "response": "<captcha_token>" }' |
| 90 | +``` |
| 91 | + |
| 92 | +The response should look like this: |
| 93 | + |
| 94 | +```json |
| 95 | +{ |
| 96 | + "success": true |
| 97 | +} |
| 98 | +``` |
| 99 | + |
| 100 | +Or, if the captcha token is invalid or expired, it will return: |
| 101 | + |
| 102 | +```json |
| 103 | +{ |
| 104 | + "success": false |
| 105 | +} |
| 106 | +``` |
| 107 | + |
| 108 | +If `success` is true, you can proceed with your app logic. |
| 109 | + |
| 110 | +### Client-side library storage |
| 111 | + |
| 112 | +Cap Standalone can also serve the widget and floating client-side library files. [Learn more](options.md#asset-server). |
0 commit comments