Skip to content

Instantly share code, notes, and snippets.

View z4nr34l's full-sized avatar
💻
QmVlcC1ib29wLCBib29wLWJlZXA=

Z4NR34L z4nr34l

💻
QmVlcC1ib29wLCBib29wLWJlZXA=
View GitHub Profile
@z4nr34l
z4nr34l / middleware.ts
Last active August 6, 2024 11:37
next-easy-middlewares multipath middleware chain
import { createMiddleware } from '@rescale/nemo';
import { internalMiddleware } from '@/app/(platform)/(personal)/_middleware';
const middlewares = {
'/(home|settings){/:path}?': internalMiddleware,
};
export const middleware = createMiddleware(
middlewares as never,
);
@z4nr34l
z4nr34l / updater.sh
Created May 31, 2024 08:14
Auto project update on dedicated server, just put it in cron :D
#!/bin/bash
# Project settings
PROJECT_DIR="<PROJECT DIR>"
# Function to log messages with date and time
log_message() {
echo "[$(date +"%Y-%m-%d %H:%M:%S")] $1"
}
@z4nr34l
z4nr34l / route.ts
Last active May 28, 2024 08:18
@rescale/cron example usage
import type { NextRequest, NextResponse } from 'next/server';
import { CronJob, type ErrorResponse } from '@rescale/cron';
// [...]
interface CombinedResponse {
updateSubscriptions: UpdateSubscriptionResponse[];
sendNewsletter: SendNewsletterResponse[];
}
@z4nr34l
z4nr34l / README.md
Created May 20, 2024 07:19
Tinybird github + vercel integration for nextjs projects.

As there is no officially supported integration that really works I've prepared a simple CI/CD pipelines to cover vercel's preview and production environments.

Instruction

1. Create 3 Tinybird workspaces:

  • <name>_dev,
  • <name>_stage,
  • <name>
@z4nr34l
z4nr34l / next-real-ip.ts
Created April 10, 2024 08:49
Simple function to fetch users real IP address in nextjs app on vercel including cloudflare proxy
/**
* The fallback IP address to use if the real IP address cannot be determined.
*/
const FALLBACK_IP_ADDRESS = '0.0.0.0';
/**
* Returns the real IP address of the client.
* @param request - The incoming request.
* @param cfProxy - Whether the client is behind a Cloudflare proxy.
* @returns The real IP address of the client.
@z4nr34l
z4nr34l / middleware.ts
Created January 7, 2024 19:03
Next.js default middleware with path matching
// example code source: https://github.com/vercel/next.js/blob/canary/examples/middleware/middleware.ts
import { NextRequest, NextResponse } from 'next/server'
export function middleware(request: NextRequest) {
if (request.nextUrl.pathname === '/about') {
return NextResponse.redirect(new URL('/redirected', request.url))
}
if (request.nextUrl.pathname === '/another') {
return NextResponse.rewrite(new URL('/rewrite', request.url))