feat(analitik): iç trafik ve bot temizliği (→ 2.9.11)
Some checks failed
Deploy / deploy (push) Has been cancelled
Some checks failed
Deploy / deploy (push) Has been cancelled
- Yönetici hesabıyla giriş yapılan cihaz kalıcı olarak ölçüm dışı (localStorage disable-rybbit); ?rybbit=off işareti de kalıcı. - Facebook önizleme, Azure ve China Mobile aralıklarına proxy kt-olcum=kapali çerezi yazar; site açılır, Rybbit yüklenmez. - 3 yeni Huawei Cloud aralığı erişim engeline eklendi. - Çerez politikası, sürüm notu ve RYBBIT-BAGLANTI.md güncellendi. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
39
src/proxy.ts
39
src/proxy.ts
@@ -1,5 +1,9 @@
|
||||
import { NextResponse, type NextRequest } from "next/server";
|
||||
import { ipEngelliMi, istemciIp } from "@/lib/engellenen-araliklar";
|
||||
import {
|
||||
ipEngelliMi,
|
||||
ipOlcumDisiMi,
|
||||
istemciIp,
|
||||
} from "@/lib/engellenen-araliklar";
|
||||
import { katalogAdresKarari } from "@/features/katalog/adres-denetimi";
|
||||
|
||||
/**
|
||||
@@ -8,6 +12,9 @@ import { katalogAdresKarari } from "@/features/katalog/adres-denetimi";
|
||||
*/
|
||||
const YOK_YOLU = "/__adres-yok";
|
||||
|
||||
/** `rybbit-yukleyici.tsx` ile aynı ad; değiştirirsen ikisini birden değiştir. */
|
||||
const OLCUM_CEREZI = "kt-olcum";
|
||||
|
||||
/**
|
||||
* Her isteğin önünde çalışır (Next "proxy" dosya konvansiyonu; eski adı
|
||||
* middleware). İki işi var:
|
||||
@@ -21,12 +28,17 @@ const YOK_YOLU = "/__adres-yok";
|
||||
* `src/features/katalog/adres-denetimi.ts`). Sayfa içi `notFound()`
|
||||
* Suspense içinde kaldığı için bunu yapamaz.
|
||||
*
|
||||
* 3. Ölçüm dışı aralıklara (Facebook önizleme tarayıcısı, Azure taraması;
|
||||
* `OLCUM_DISI_ARALIKLAR`) `kt-olcum=kapali` çerezi yazmak. Sayfa açılır,
|
||||
* yalnız Rybbit betiği yüklenmez (`rybbit-yukleyici.tsx`).
|
||||
*
|
||||
* Kapsam dışı: `_next/static` ve `_next/image` (sayfa 403 alınca tarayıcı
|
||||
* bunları zaten istemez; gerçek kullanıcının varlık isteklerine ek maliyet
|
||||
* binmesin) ve `/api/saglik` (konteyner içi sağlık kontrolü, XFF başlığı yok).
|
||||
*/
|
||||
export function proxy(request: NextRequest) {
|
||||
if (ipEngelliMi(istemciIp(request.headers))) {
|
||||
const ip = istemciIp(request.headers);
|
||||
if (ipEngelliMi(ip)) {
|
||||
return new NextResponse("Erişim engellendi.", {
|
||||
status: 403,
|
||||
headers: { "content-type": "text/plain; charset=utf-8" },
|
||||
@@ -41,17 +53,30 @@ export function proxy(request: NextRequest) {
|
||||
// notFound() eski davranışla (200 + noindex) yine çalışır.
|
||||
console.error("[proxy] adres denetimi", hata);
|
||||
}
|
||||
let yanit: NextResponse;
|
||||
if (karar?.tur === "yok") {
|
||||
return NextResponse.rewrite(new URL(YOK_YOLU, request.url));
|
||||
}
|
||||
if (karar?.tur === "yonlendir") {
|
||||
yanit = NextResponse.rewrite(new URL(YOK_YOLU, request.url));
|
||||
} else if (karar?.tur === "yonlendir") {
|
||||
const hedef = request.nextUrl.clone();
|
||||
hedef.pathname = karar.yol;
|
||||
return NextResponse.redirect(hedef, 308);
|
||||
yanit = NextResponse.redirect(hedef, 308);
|
||||
} else {
|
||||
yanit = NextResponse.next();
|
||||
}
|
||||
return NextResponse.next();
|
||||
|
||||
if (ipOlcumDisiMi(ip)) {
|
||||
// httpOnly DEĞİL: istemcideki yükleyici okur. Kişisel veri taşımaz.
|
||||
yanit.cookies.set(OLCUM_CEREZI, "kapali", {
|
||||
path: "/",
|
||||
maxAge: 60 * 60 * 24 * 30,
|
||||
sameSite: "lax",
|
||||
secure: true,
|
||||
});
|
||||
}
|
||||
return yanit;
|
||||
}
|
||||
|
||||
|
||||
export const config = {
|
||||
matcher: ["/((?!_next/static|_next/image|api/saglik).*)"],
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user