CMS API Endpoints

Documentation untuk API endpoints CMS Kiryuu.

Authentication Endpoints

POST /api/cms/login

Login ke admin panel.

Request Body:

{
  "username": "admin",
  "password": "admin123"
}

Success Response (200):

{
  "success": true,
  "message": "Login berhasil"
}

Error Response (401):

{
  "success": false,
  "message": "Username atau password salah"
}

Cookies Set:


POST /api/cms/logout

Logout dari admin panel.

Success Response (200):

{
  "success": true,
  "message": "Logout berhasil"
}

Cookies Cleared:


GET /api/cms/validate

Validate current session.

Success Response (200):

{
  "authenticated": true
}

or

{
  "authenticated": false
}

Configuration Endpoints

GET /api/cms/config

Get current site configuration.

Authentication Required: Yes (Cookie: admin_session)

Success Response (200):

{
  "success": true,
  "data": {
    "website": "https://kiryuu.io",
    "title": "Kiryuu ID",
    "seoTitle": "Kiryuu ID - Baca Komik...",
    "description": "...",
    "hero": {
      "title": "Kiryuu ID",
      "text": "Baca Komik...",
      "image": {
        "src": "/assets/images/logo-kiryuu.avif",
        "alt": "..."
      }
    },
    "about": {
      "text": "..."
    },
    "socialLinks": [
      {
        "text": "Facebook",
        "href": "https://facebook.com/..."
      }
    ],
    "keywords": {
      "text": "..."
    }
  }
}

Error Response (401):

{
  "success": false,
  "message": "Unauthorized"
}

POST /api/cms/config

Update site configuration.

Authentication Required: Yes (Cookie: admin_session)

Request Body:

{
  "config": {
    "website": "https://kiryuu.io",
    "title": "New Title",
    "seoTitle": "New SEO Title",
    "description": "New description",
    "hero": {
      "title": "New Hero Title",
      "text": "New hero text",
      "image": {
        "src": "/path/to/image.jpg",
        "alt": "Image alt text"
      }
    },
    "about": {
      "text": "New about text"
    },
    "socialLinks": [
      {
        "text": "Platform Name",
        "href": "https://..."
      }
    ],
    "keywords": {
      "text": "keyword1, keyword2"
    },
    "websiteManga": "https://...",
    "recentPostLimit": 3
  }
}

Success Response (200):

{
  "success": true,
  "message": "Konfigurasi berhasil disimpan"
}

Error Response (401):

{
  "success": false,
  "message": "Unauthorized"
}

Error Response (500):

{
  "success": false,
  "message": "Gagal menyimpan konfigurasi"
}

Usage Examples

JavaScript/Fetch

// Login
const login = async (username, password) => {
  const response = await fetch('/api/cms/login', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({ username, password }),
  });
  return await response.json();
};

// Get Config
const getConfig = async () => {
  const response = await fetch('/api/cms/config');
  return await response.json();
};

// Update Config
const updateConfig = async (config) => {
  const response = await fetch('/api/cms/config', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({ config }),
  });
  return await response.json();
};

// Logout
const logout = async () => {
  const response = await fetch('/api/cms/logout', {
    method: 'POST',
  });
  return await response.json();
};

cURL Examples

# Login
curl -X POST http://localhost:4321/api/cms/login \
  -H "Content-Type: application/json" \
  -d '{"username":"admin","password":"admin123"}' \
  -c cookies.txt

# Get Config (with cookie)
curl http://localhost:4321/api/cms/config \
  -b cookies.txt

# Update Config (with cookie)
curl -X POST http://localhost:4321/api/cms/config \
  -H "Content-Type: application/json" \
  -b cookies.txt \
  -d '{"config":{...}}'

# Logout (with cookie)
curl -X POST http://localhost:4321/api/cms/logout \
  -b cookies.txt

Security Notes

  1. Authentication: All config endpoints require valid session cookie
  2. Session Expiry: Sessions expire after 24 hours
  3. HTTPS Only: Use HTTPS in production
  4. Rate Limiting: Consider implementing rate limiting for login endpoint
  5. CORS: Configure CORS policies appropriately

Error Handling

All endpoints return JSON responses with the following structure:

type APIResponse = {
  success: boolean;
  message?: string;
  data?: any;
};

HTTP Status Codes:


For more information, see CMS_README.md