# Managing Sites

This guide covers how to create and manage sites through the Filebase web console and SDK.

## Creating a Site

### Using the Web Console

1. Navigate to the **Sites** section in the Filebase dashboard.
2. Click **Create Site** in the top right corner.
3. Enter a **site name** following these requirements:
   * 3-63 characters long
   * Lowercase letters, numbers, and dashes only
   * Must start and end with a letter or number
   * Must be globally unique across all Filebase users
4. Click **Create** to create the site.
5. Your site is now created with an IPNS name. The subdomain `{site-name}.myfilebase.site` is now reserved for your site.

{% hint style="info" %}
After creating a site, you'll need to associate it with a CID to make it accessible.
{% endhint %}

## Associating Content with a Site

Once your site is created, you need to associate it with an IPFS CID:

### Using the Web Console

1. Navigate to the **Sites** section and select your site.
2. Click **Update Site** or **Set CID**.
3. Enter the **CID** of the content you want to publish. This should be the root CID of your website files (typically an IPFS directory containing your `index.html` and other assets).
4. Click **Save** to publish the content.
5. Your site will be accessible at `https://{site-name}.myfilebase.site` within a few minutes.

### Using the @filebase/sdk

You can also manage sites programmatically using the Filebase SDK:

```javascript
import { SitesClient } from '@filebase/sdk';

// Initialize the client
const sitesClient = new SitesClient({
  credentials: {
    accessKeyId: 'YOUR_ACCESS_KEY',
    secretAccessKey: 'YOUR_SECRET_KEY'
  }
});

// Create a new site
const site = await sitesClient.create('my-website');
console.log('Site created:', site.name);
console.log('IPNS Name:', site.ipnsName);

// Associate a CID with the site
await sitesClient.publish('my-website', 'QmYourContentCID...');
console.log('Site published!');

// Get site details
const siteDetails = await sitesClient.get('my-website');
console.log('Current CID:', siteDetails.cid);
```

## Updating Site Content

To update your site with new content:

1. Upload your new website files to an IPFS bucket to get a new CID.
2. Navigate to your site in the **Sites** section.
3. Click **Update Site** and enter the new CID.
4. Click **Save** to publish the update.

The IPNS record will be updated to point to the new CID. Your URL remains the same, but visitors will see the new content after the TTL expires (typically within 5 minutes).

{% hint style="success" %}
Your site URL never changes when you update content. This makes it safe to share links and set up DNS records without worrying about broken URLs.
{% endhint %}

## Viewing Site Details

From the Sites section, you can view:

* **Site Name**: Your chosen site name
* **Subdomain**: The full URL (`{site-name}.myfilebase.site`)
* **IPNS Name**: The underlying IPNS key (k51qzi5uqu5d...)
* **Current CID**: The IPFS CID currently published to the site
* **Custom Domain**: Any custom domain configured for the site
* **Created Date**: When the site was created
* **Last Updated**: When the site content was last changed

## Deleting a Site

To delete a site:

1. Navigate to the **Sites** section and select the site you want to delete.
2. Click **Delete Site**.
3. Confirm the deletion.

{% hint style="warning" %}
Deleting a site releases the site name, making it available for other users. This action cannot be undone. Your IPFS content will remain pinned in your bucket, but the IPNS name and subdomain will no longer work.
{% endhint %}

## Best Practices

### Preparing Your Website Files

Before creating a site, ensure your website files are properly structured:

* Include an `index.html` file at the root of your directory
* Use relative paths for all assets (CSS, JS, images)
* Test your site locally before uploading

### Uploading Website Content

1. Create an IPFS bucket if you don't have one already.
2. Upload your website folder to the bucket. The folder will receive a CID.
3. Use this folder CID when associating content with your site.

### Version Management

Consider keeping previous versions of your site:

* Use descriptive folder names when uploading (e.g., `website-v1.2.0`)
* Keep old CIDs documented in case you need to rollback
* Test new versions on a staging site before updating production
