Code Explainers

Code explainers tagged #edge-runtime

javascript
import OpenAI from 'openai';
 
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
 

Streaming OpenAI tokens from a Next.js edge route

streaming edge-runtime readablestream
Advanced 9 steps
javascript
import { NextResponse } from 'next/server';
import { Redis } from '@upstash/redis';
 
export const runtime = 'edge';

A deduped page-view counter in Next.js

edge-runtime redis rate-limiting
Intermediate 8 steps
javascript
import { NextResponse } from 'next/server';
import { jwtVerify } from 'jose';
 
const PROTECTED_PREFIXES = ['/dashboard', '/settings', '/billing'];

Gating routes with Next.js middleware and JWTs

authentication middleware jwt
Intermediate 8 steps