Featured Projects
001: ADVANCED DDOS MITIGATION & GLOBAL SERVER OPTIMIZATION
A serverless solution for robust DDoS protection and worldwide low-latency content delivery.
Tech Stack:
- Cloudflare Workers
- CDN
- DNS
- Express.js
- Linux
- Docker
- Ansible
- Prometheus
- Grafana
export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
const responseHeaders = { 'Cache-Control': 'no-store', 'X-Robots-Tag': 'noindex, nofollow' };
const RATE_LIMIT = 1; // rate limit per IP
const TIME_WINDOW = 60; // Time window in seconds (60 seconds)
try {
// Retrieve the client's IP address from the 'x-real-ip' header
const ip = request.headers.get('x-real-ip');
if (!ip) {
return new Response('IP address not found', { status: 400, headers: responseHeaders });
}
// Retrieve the current count for this IP from KV store
const countResult = await env.RATE_LIMIT_STORE.get(ip);
let count = countResult ? parseInt(countResult) : 0;
// Check if the rate limit has been exceeded
if (count >= RATE_LIMIT) {
return new Response('Rate limit exceeded', { status: 429, headers: responseHeaders });
}
// Increment the count and update the KV store
await env.RATE_LIMIT_STORE.put(ip, (count + 1).toString(), { expirationTtl: TIME_WINDOW });
// Existing VM selection logic
const { country, city } = request.cf;
const vmIpsArray = env.VMS.split(',');
const selectedVmIps = selectVmsBasedOnLocation(vmIpsArray, { country, city });
const vmStatuses: VMStatus[] = await Promise.all(
selectedVmIps.map((ip: string) =>
checkLatency(ip).catch((error) => {
console.log("Error checking latency for IP: ", ip);
return { ip, latency: Infinity, available: false };
})
)
);
const availableVms = vmStatuses.filter((vm) => vm.available && vm.latency !== Infinity);
if (availableVms.length === 0) {
console.error('All VMs are unavailable. Retrying after a delay...');
return new Response('No available servers', { status: 503, headers: responseHeaders });
}
const bestVm = availableVms.reduce((prev, curr) => (prev.latency < curr.latency ? prev : curr));
return new Response(bestVm.ip, { headers: responseHeaders });
} catch (error) {
if (error instanceof Error) {
console.error("Unexpected error: ", error.message);
} else {
console.error("Unexpected error: ", error);
}
return new Response('An unexpected error occurred', { status: 500, headers: responseHeaders });
}
},
};
002: FULL-STACK E-COMMERCE PLATFORM WITH CUSTOM CMS
Comprehensive e-commerce platform featuring Next.js for SSR, SSG, and ISR, with custom CMS and Stripe integration.
Tech Stack:
- React
- Next.js 14
- Tailwind CSS
- Strapi
- Stripe API
- Cloudflare Pages
export async function GET(req: NextRequest, { params }: any) {
const API = process.env.API_URL;
const AUTH_TOKEN = process.env.API_TOKEN;
const name = params.product;
try {
const response = await fetch(
`${API}`, // template literal for dynamic URL
{
headers: {
Authorization: `Bearer ${AUTH_TOKEN}`,
},
}
);
if (!response.ok) {
throw new Error("Error fetching products");
}
const jsonResponse = await response.json();
return new Response(JSON.stringify(jsonResponse), {
status: 200,
headers: {
"Content-Type": "application/json",
cache: "no-cache",
},
});
} catch (error) {
return new Response(
JSON.stringify({ message: "Error fetching products" }),
{
status: 500,
headers: {
"Content-Type": "application/json",
},
}
);
}
}
003: COMPLETE CUSTOM CMS API
Robust backend for content management systems with Redis caching, MariaDB connectivity, and JWT authentication.
Tech Stack:
- TypeScript
- Node.js
- Express.js
- Redis
- MariaDB
- JWT
const router = Router();
router.get("/verify-discord", async (req: Request, res: Response) => {
try {
const code = req.query.code;
if (typeof code !== "string") {
return res
.status(400)
.send({ success: false, message: "Invalid or missing code" });
}
const isValidCode = await verifyDiscordCode(code);
if (!isValidCode) {
return res.status(401).send({ success: false, message: "Invalid code" });
} else {
const getRolesClaimed = await getClaimedDiscordCode(code);
if (!getRolesClaimed) {
return res.status(200).send({
success: false,
message: "Roles already claimed",
});
}
const testerRole = await getDiscordAccountID(code);
await claimDiscordCode(code);
return res.status(200).send({
success: true,
message: "Code verified successfully",
role: testerRole,
});
}
} catch (err) {
console.error("Error in /verify-discord:", err);
return res
.status(500)
.send({ success: false, message: "An unknown error occurred" });
}
});
export default router;