# Deployment and subdomains

> Deploy your app on Cloudflare or any host, and request a subdomain such as name.hasanat.dev.

Source: https://platform.hasanat.dev/en/docs/services/deploy-and-subdomains/

Deploy your app wherever suits you, then request a hasanat.dev subdomain if you want one. A maintainer connects it in the way that fits your host.

If you built your app from the starter, the easiest route is [managed hosting](/docs/services/managed-hosting/) (Arabic, with English terms): your code stays in your repository and is hosted in Hasanat's account with a database and a subdomain, after approval of the request and of every release. The pilot is open for public repositories; the private-repository path is not enabled yet. The instructions below are for deployments you run yourself in your own Cloudflare account.

## Deploying the starter

The starter uses Astro 5 with Cloudflare Pages: `wrangler.toml` contains `pages_build_output_dir = "./dist"`. You need a Cloudflare account, then:

```sh
npx wrangler login
npm run build
npx wrangler pages deploy dist/
```

- Set the project name in `wrangler.toml`, plus `PUBLIC_SITE_URL` and `PUBLIC_APP_NAME` under `[vars]`.
- Shared sign-in needs no secrets. If your app needs a secret of its own, set it with `npx wrangler pages secret put NAME`, never in the repository.
- The starter's `src/middleware.ts` adds basic security headers to every page, and its `public/_headers` file adds them to static files.
- Deploy only after `npm run check` and `npm run build` pass.

:::note[Astro 6 and later]
The Cloudflare adapter for Astro 6 and later deploys to Workers only, not Pages. You build with `astro build`, deploy with `npx wrangler deploy`, and attach the subdomain to the Worker as a Custom Domain. The new hasanat.dev and this platform both run on Workers and are built with Astro 7.
:::

## Automatic deploys from GitHub

You can deploy on every merge to the main branch with GitHub Actions:

```yaml
# .github/workflows/deploy.yml
name: Deploy
on:
  push:
    branches: [main]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 22
      - run: npm ci
      - run: npm run build
      - uses: cloudflare/wrangler-action@v3
        with:
          apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
          command: pages deploy dist/ --project-name=your-app-name
```

Store `CLOUDFLARE_API_TOKEN` as a secret in the repository's GitHub settings, never in the code.

That example uses your own hosting permissions. Managed hosting does not place a Hasanat account token in a builder's repository, and a GitHub push cannot publish to production by itself.

## Request a subdomain

Request a "subdomain" from the [shared services in your dashboard](https://platform.hasanat.dev/dashboard/services) once your app works. Include:

- **The name you want:** lowercase letters, digits, and hyphens, one level only, such as `your-app.hasanat.dev`. Shared sign-in does not accept two-level names such as `app.your-app.hasanat.dev`.
- **Where the app runs:** a Cloudflare Pages project or Worker, and in which account, or another host.
- **Its current URL:** for example `your-app.pages.dev`.

## How the subdomain is connected

### Worker in the Hasanat account

- You: nothing.
- The maintainer: adds the name as a Custom Domain on the Worker; Cloudflare creates the DNS record and certificate.

### Pages project in the Hasanat account

- You: nothing.
- The maintainer: adds the domain in the project's settings; Cloudflare creates the DNS record.

### Pages project in your account

- You: add the domain first: **Workers & Pages** → your project → **Custom domains** → **Set up a domain**.
- The maintainer: adds a CNAME record pointing to `your-app.pages.dev`.

### Another host, such as Vercel or Netlify

- You: add the domain in the host's settings, and copy the records it asks for into the request.
- The maintainer: adds the DNS records the host asked for.

### Worker in your own Cloudflare account

It cannot be connected directly: Cloudflare requires the Worker to be in the account that owns the hasanat.dev zone. Agree in the request on deploying to Pages or to the Hasanat account.

After it is connected, open `https://name.hasanat.dev` and check that the page loads with a valid certificate. If your app uses shared sign-in, try it now: it does not work on `localhost`, `*.pages.dev`, or `*.workers.dev`.

## Hosting outside Cloudflare

You don't have to use Cloudflare. Deploy your app anywhere and request a subdomain that points to it. Shared sign-in works when the app is served on its hasanat.dev subdomain and its server asks the auth service for the session, as described in [sign-in](/en/docs/services/sign-in/).
