
DINHDANH Creator · Bài AM10 · URL · Dữ liệu rỗng · Rate limit
link · rỗng · giới hạn gọi API
URL visitor khác API vdisk. Đọc lần đầu luôn rỗng - không phải lỗi. Mutation quá dày có thể bị chặn IP tạm thời.
Mục tiêu: Link đúng domain; xử lý content: [] bình thường; luôn addRoute khi publish; bọc try/catch khi bị rate limit.
Trước: AM09 · Sau: AM11 (System files & CMS)
A. URL tuyệt đối - vì sao quan trọng
Platform inject blog/detail.html.
→ PHP đọc routes.json → serve HTML template
→ Head có
site_url trong JS luôn là domain platform - có thể khác host với
| Cách viết | Kết quả |
|---|---|
href="tag/js" | ✅ Đúng - slug dưới gốc app |
getAbsoluteUrl('tag/js') | ✅ Rõ ràng - dùng cho location.href, JS build link |
href="/tag/js" | ❌ Root domain - mất url_name |
href="../tag/js" | ❌ .. nhảy ra ngoài app |
href="blog/detail.html" | ❌ File template FS - visitor cần route slug, không phải .html |
Quy tắc: Link điều hướng - getAbsoluteUrl(slug) hoặc href="slug" (không / đầu, không .., không .html). Slug phải có trong routes.json (addRoute).
Helper - copy vào HTML app
/** Ưu tiên- đúng cả custom domain */ function getAppBaseUrl() { const base = document.querySelector('base[href]')?.href if (base) return base.replace(/\/$/, '') + '/' const site = (window.appifio?.global?.apps?.site_url || window.location.origin).replace(/\/$/, '') const name = window.appifio?.global?.apps?.url_name || '' return name ? `${site}/${name}/` : `${site}/` } /** path = slug route: '' | 'admin' | 'my-post' | 'tag/javascript' */ function getAbsoluteUrl(path) { const base = getAppBaseUrl().replace(/\/$/, '') const segment = String(path || '').replace(/^\//, '') return segment ? `${base}/${segment}` : `${base}/` }
Ví dụ (url_name=test-blog) | Kết quả |
|---|---|
getAbsoluteUrl('') | Trang chủ app |
getAbsoluteUrl('admin') | Panel admin |
getAbsoluteUrl('login') | Trang đăng nhập |
getAbsoluteUrl('bai-viet-ve-ai') | Chi tiết bài (route slug) |
getAbsoluteUrl('tag/javascript') | Trang tag lồng |
B. Dữ liệu rỗng & route bắt buộc
Hai khái niệm tách biệt - đừng nhầm:
| Tầng | Khi chưa có | Ví dụ |
|---|---|---|
| API vdisk (dữ liệu JSON) | success: true + rỗng - không 404 | readList → content: [] |
| Physical FS (HTML trên disk) | success: false nếu chưa tạo | readFsFile('blog/detail.html') |
| URL visitor (routing) | HTTP 404 trang web | Slug không có trong routes.json |
B.1 - Đọc vdisk lần đầu
| Method | Khi chưa có dữ liệu |
|---|---|
readList | content: [] |
readFile (flat) | content: "" |
readFile (indexed + id) | content: null (không tìm thấy / bị lọc) |
async function loadBlogs() {
const result = await appifio_client.appifio_readList('blog.json', ['id','title','slug'])
if (result?.success) return result.data.content || [] // [] lần đầu - bình thường
return []
}
// Thêm bài đầu tiên - backend tự tạo sổ
await appifio_client.appifio_appendData('blog.json', { title, slug, content })
// Flat config - giữ default nếu rỗng
let config = { theme: 'light' }
const res = await appifio_client.appifio_readFile('config.json')
if (res?.success && res.data.content && typeof res.data.content === 'object') {
config = res.data.content
}// Expect lỗi khi file chưa có - vdisk KHÔNG làm vậy
if (!result.success) { /* never on first read */ }
// JSON.parse - Aura đã parse sẵn
const items = JSON.parse(result.data.content)
// writeFile cho list - phá sharding indexed
await appifio_client.appifio_writeFile('blog.json', JSON.stringify([...]))B.2 - Route bắt buộc cho URL visitor
Mặc định chỉ /urlname/ serve index.html. Mọi slug khác phải có entry trong routes.json - nếu không, visitor nhận 404 (không liên quan API vdisk).
// ❌ SAI - có data nhưng visitor 404
await appifio_client.appifio_appendData('blog.json', blogData)
// ✅ ĐÚNG - data + route + template HTML đã có trên FS
const { data: { id } } = await appifio_client.appifio_appendData('blog.json', blogData)
await appifio_client.appifio_addRoute(blogData.slug, 'blog/detail.html', 'blog')
// Route lồng tag / category
await appifio_client.appifio_addRoute('tag/javascript', 'blog/tag.html', 'tag')
await appifio_client.appifio_addRoute('category/cong-nghe', 'blog/category.html', 'category')
// Xóa bài → xóa route tương ứng
await appifio_client.appifio_updateData('blog.json', id, null)
await appifio_client.appifio_removeRoute(slug)addRoute map slug → file HTML trên Physical FS - file blog/detail.html phải tồn tại (Panel hoặc writeFsFile). Chi tiết method: AM05.
C. Rate limit & IP block

Giới hạn tính theo IP + link (url_name) - mỗi app độc lập.
| Loại | Bị đếm? | Khi vượt |
|---|---|---|
| Mutation (append, update, write, upload, route, đổi mật khẩu…) | ✅ Cao trong cửa sổ ngắn | Block IP tạm thời |
executeBackendFunction | ✅ Riêng - cửa sổ dài hơn | Block IP tạm thời |
| Login sai mật khẩu | ✅ Ngưỡng thấp | Block IP tạm thời |
| Read (readList, getRoutes, getSession…) | ❌ Không limit | - |
logout | ❌ Không tính quota mutation | - |
Khi IP bị block: HTTP 429, client map err.blocked === true. Bạn không nhận thời gian còn lại hay lý do chi tiết - UI báo chung “Thử lại sau”.
try {
await appifio_client.appifio_appendData('contacts.json', data)
} catch (err) {
if (err.blocked) {
alert('IP tạm bị chặn do gọi API quá nhiều. Vui lòng thử lại sau.')
return
}
if (err.httpStatus === 401) { /* phiên hết hạn - chuyển login */ }
throw err
}Checklist AM10:
- Redirect / link dùng
getAbsoluteUrl, không/đầu? - List rỗng =
[], không coi là lỗi? - Publish có
addRoute; xóa córemoveRoute? - Form public có
try/catch+err.blocked?
Điều hướng nội bộ (cùng ngôn ngữ)
DINHDANH Creator · Loạt Method · AM10