
Dil 🇹🇷 Türkçe
Val Town Kurulumu
Val Town Uygulamalarına Canlı Yorum Ekleme
Val Town Deno üzerinde TypeScript çalıştırır, bu yüzden bir val gerçek bir sunucudur. Bu, FastComments için iyi bir uyum sağlar: widget sayfada bir script etiketi olarak bulunur ve Secure SSO gibi bir gizli bilgiye ya da bir webhook doğrulamaya ihtiyaç duyan her şey aynı val içinde sunucu tarafında çalıştırılabilir.
Bu kılavuz, yorum widget'ını bir HTTP val'ına eklemeyi, bir indeks sayfasında yorum sayılarını göstermeyi, kullanıcıları zaten sahip oldukları Val Town hesabı ile oturum açtırmayı ve yorum webhook'larını almayı kapsar.
Bunu denemek için bir hesaba ihtiyacınız yok. Örnekler tenantId: "demo" adlı paylaşılan bir sandbox kullanır ve Adım 2, kendi sandbox'ınıza geçişi kapsar.
Adım 1: Widget'ı Ekle 
The widget is a script tag and a container element, so it drops into whatever your val already renders. This example uses Hono JSX, which is what Val Town's HTTP templates use.
Run 
Göndermeden önce bir urlId seçin
urlId decides which thread a comment lands in. Leave it unset and it defaults to a cleaned version of the current page URL, which is exactly the thing that changes on Val Town: a val has a long *.web.val.run hostname until you claim a subdomain, branches get their own URLs, and renaming a page changes the path. Each variation silently becomes a separate, empty thread, and the symptom reads as "my comments disappeared".
Set it to something stable that you control, like the post slug or a database id, as above. Pass url too, so notification emails and the moderation tools can link back to the real page.
JavaScript olmadan yorumları koruma
FastComments renders a full thread server-side, which a val can drop into a <noscript> block:
Run 
URL-encode the parameters. The server-side version supports anonymous and logged-in commenting, SSO, and nested replies.
Adım 2: Kendi Hesabınızı Kullanın 
tenantId: "demo" ortak bir halka açık sandbox'tur. Kayıt olmadan çalışır, bu yüzden örneklerde kullanılır, ancak FastComments deneyen diğer herkes aynı konulara yazar ve herkes bunları denetleyebilir. Önemli bir şeyi yayınlamadan önce değiştirin.
Kiracı kimliğiniz API gizli sayfasında bulunur.
Bir kiracı kimliği herkese açıktır ve tarayıcı kodunda bulunur. API gizli anahtarı böyle değildir ve bu sayfadaki hiçbir şey ona ihtiyaç duymaz.
Bir ortam değişkeninden okuyun
Val Town değerleri ücretsiz katmanda herkese açıktır, bu yüzden kaynakları herkes tarafından okunabilir. Hassas tüm verileri ortam değişkenlerinde tutun, Deno.env.get ile okuyun:
Run 
Bu, Val Town'da ikinci bir neden dolayı genellikle olduğundan daha önemlidir: bir değeri yeniden karıştırmak ortam değişkeni anahtarlarını kopyalar, ancak değerlerini kopyalamaz. Ortam değişkeninde tutulan bir gizli anahtar, değerinizi başka birinin hesabına taşımaz. Bir dosyaya yazılan bir gizli anahtar ise taşır.
"demo"'ya geri dönmek, değeri kendi kiracısını ayarlamadan önce yeniden karıştıran herkes için çalışır durumda tutar.
AB hesapları
Bir hesap, verileri ve anahtarları tek bir bölgede bulunur. Eğer hesabınız eu.fastcomments.com üzerinde oluşturulduysa, her widget yapılandırması da region: "eu" gerektirir ve betikler cdn-eu.fastcomments.com adresinden yüklenir. Aksi takdirde ikisini de olduğu gibi bırakın.
İndeks Sayfasındaki Yorum Sayıları 
On an index page, don't render one comment-count widget per row. That is one request per post. Use the bulk count, which takes a single request for the whole page.
Mark each row with the urlId its thread uses, then load the bulk widget once:
Run 
The script finds every .fast-comments-count element on the page and fills in its count.
data-fast-comments-url-id has to match the urlId that post's comment widget uses. If the widget uses the slug, the marker uses the slug. A mismatch shows zero on a thread that has comments.
The script polls for window.FastCommentsBulkCountConfig, so it does not matter whether you set the config before or after the script tag.
std/oauth ile Güvenli SSO 
If your val already knows who the visitor is, Secure SSO hands that identity to the widget so they never see a second login. There are no endpoints to build and nothing to call at runtime: you compute three values server-side and pass them in the widget config.
Val Town ships zero-config login with std/oauth, so the visitor can sign in with the Val Town account they already have. Swap that for whatever your app uses; the FastComments half does not change.
Build the payload on the server
The API secret signs the payload and must never reach browser code. Install the SDK from npm, which works on Val Town's Deno runtime as-is:
Run 
getPayload() returns { userDataJSONBase64, verificationHash, timestamp }. Those three values are all that reach the browser. The secret signs them and is then dropped, so nothing in the page lets a reader forge a different user.
Pass it to the widget
Run 
oauthMiddleware adds GET /auth/login, GET /auth/callback and POST /auth/logout for you. Note that logout is a POST, while the widget navigates to logoutURL with a GET, so point logoutURL at a small route of your own that submits the POST.
When the visitor is logged out, pass sso with only a loginURL. The widget then shows a login prompt instead of an anonymous comment box.
Things that go wrong
timestamp is epoch milliseconds, must not be in the future, and must not be more than two days old. Generate it on the server in the same request that computes the hash. Generating it in the browser is the classic failure: the value differs from the one that was hashed and every comment is rejected.
Never set isAdmin or isModerator from the identity provider. Signing in with a Val Town account says nothing about who should moderate your site.
See the SSO guide for the full field list, group-gated threads, and badges.
Webhook'ları Alma 
A val, doğal bir webhook alıcısıdır: sabit bir URL'ye sahiptir, bir imzayı doğrulayabilir ve SQLite ile blob depolama yerleşiktir.
FastComments, ${timestamp}.${body} ifadesini hesabınızın API gizli anahtarıyla imzalar ve iki başlık gönderir:
Run 
Yöntem olayı taşır: oluşturulan veya güncellenen bir yorum için PUT, silinen bir yorum için DELETE.
Run 
Sorun yaratan iki şey
Ham baytları doğrulayın. JSON'u ayrıştırıp yeniden serileştirmek, anahtar sırasını ve boşlukları değiştirir, bu yüzden hash farklı olur ve her teslimat belirgin bir neden olmadan başarısız olur. Bu, bir webhook alıcısının “sadece çalışmıyor” olmasının yaygın nedenidir.
Sabit zamanlı karşılaştırma yapın. İmza üzerinde basit bir === ifadesi, kaç baytın eşleştiğini sızdırır ve bu, tek tek bir baytı taklit etmek için yeterlidir.
Olayları işleme
Hızlı yanıt verin. FastComments, 2xx olmayan bir yanıt alındığında yeniden deneme yapar ve sürekli başarısız olan bir uç nokta sonunda otomatik olarak devre dışı bırakılır, bu yüzden gerçek işi yanıt verdikten sonra yapın, satır içinde değil.
Bu işlemi yorum kimliği üzerinde idempotent (tekrarlanabilir) hâle getirin. Bir yeniden deneme, yeni bir zaman damgası ile yeniden imzalanır ve aynı yorum kimliği düzenleme ve silme sırasında tekrar gelir, bu yüzden tutarlı bir şekilde yinelenenleri ayıklamak için sabit bir şey yoktur.
Örnek Vals 
Four public vals you can remix, each covering one piece of this guide.
Blog with comments (live) bir Markdown blogudur, her gönderinin altında bir konu başlığı ve indeksde toplu yorum sayıları bulunur. Karıştırdığınız anda çalışır ve bir ortam değişkeni onu kendi hesabınıza yönlendirir.
SSO demo (live) ziyaretçiyi Val Town hesabıyla oturum açtırır ve bu kimliği widget'a verir, böylece ikinci bir oturum açma gerekmez.
Webhook receiver (live) her teslimatta HMAC imzasını doğrular ve olayları SQLite'da saklar. Test bir yük imzalayan ve kendisine teslim eden bir düğmesi vardır, böylece gerçek bir webhook yapılandırmadan önce doğrulamanın başarılı olduğunu izleyebilirsiniz.
Agent skills (live) FastComments ajan becerilerini içeren bir kütüphanedir; widget, SSO, REST API, moderasyon ve Disqus'tan geçişi kapsar. Bunu karıştırdığınızda Val Town'un ajanı Townie, skills/ içindeki becerileri otomatik olarak alır, böylece ajanınız sohbet içine belge yapıştırmadan yorumları nasıl bağlayacağını bilir.
Aynı beceriler, npx skills add fastcomments/skills komutuyla başka bir yerde de kurulabilir.
Alan Adı Hataları 
Once you switch off the demo tenant, the widget may refuse to load with an authorization error. This is because FastComments doesn't know it's supposed to allow your account to be used on that domain.
Hesabınıza sitenizi eklemek için buraya gidin.
Val Town burada ikinci bir bakışa değer, çünkü bir val birden fazla ana bilgisayar adından erişilebilir:
- Her HTTP val, uzun bir varsayılan uç noktaya sahiptir,
<org>--<id>.web.val.run. - Özel bir alt alan adı talep etmek
<name>.val.runekler. - Bir özel alan adı üçüncüsünü ekler.
- Şubeler kendi URL'lerini alır.
Widget'ı hizmet verdiğiniz tüm ana bilgisayar adlarını ekleyin. Ayarları yaptıktan sonra bir alt alan adı talep ederseniz, onu da ekleyin; aksi takdirde widget eski URL'de çalışır ve yeni URL'de başarısız olur.