Skip to content

Instantly share code, notes, and snippets.

View nathanclevenger's full-sized avatar
🚀

Nathan Clevenger nathanclevenger

🚀
View GitHub Profile
@danawoodman
danawoodman / Deploying CloudFlare Workers via CloudFlare Pages in a Turborepo monorepo.md
Last active August 9, 2025 20:07
Deploying CloudFlare Workers via CloudFlare Pages in a Turborepo monorepo

Deploying Cloudflare Workers via Cloudflare Pages in a Turborepo monorepo

Whew, what a mouthful.

Cloudflare Workers is an excellent platform for deploying a variety of applications but it has some limitations compared to Cloudflare's other product, Pages.

Pages gives you git integration which gives you auto-deploying via git push as well as pull request preview deployment links so you can test out features before pushing to production.

However, it's not super clear how to deploy a bare worker to Cloudflare Pages as Pages is more tailored right now for apps (SvelteKit, Astro, Next, etc), that is why I wrote up this little guide.

@khalidx
khalidx / node-typescript-esm.md
Last active August 10, 2025 12:07
A Node + TypeScript + ts-node + ESM experience that works.

The experience of using Node.JS with TypeScript, ts-node, and ESM is horrible.

There are countless guides of how to integrate them, but none of them seem to work.

Here's what worked for me.

Just add the following files and run npm run dev. You'll be good to go!

package.json

@SomeHats
SomeHats / runDevBrowser.mjs
Last active February 26, 2025 16:13
A hacky local version of cloudflare's browser rendering API. To use this, copy either runDevBrowser.ts or runDevBrowser.mjs and install the puppeteer and ws packages from npm. Run the dev server alongside wranger with `node runDevServer.mjs` or `tsx runDevServer.ts`
/* eslint-disable no-console */
/***
* This is a little server that emulates the protocol used by cloudflare's browser rendering API. In
* local development, you can run this server, and connect to it instead of cloudflare's (strictly
* limited) API. e.g. in your worker you might use a function like this:
*
* ```ts
* import { Browser, launch as launchPuppeteer } from '@cloudflare/puppeteer'
* function launchBrowser(env: Environment) {
* if (env.LOCAL_BROWSER_ORIGIN) {
@DrMint
DrMint / ExampleCollection.ts
Last active April 8, 2025 06:59
Grid View for Payload Uploads Collections
import { CollectionConfig } from "payload/types";
import { UploadsGridView } from "../../components/UploadsGridView/UploadsGridView";
export const Media: CollectionConfig = {
slug: "media",
admin: {
components: { views: { List: UploadsGridView } } // Set the List view to use the Grid view,
},
upload: {
staticURL: "/media",
@paulpopus
paulpopus / middleware.ts
Created August 11, 2023 07:26
Nextjs Middleware for Payload authentication to redirect users based on authentication
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
import { CheckUserDocument } from '@/graphql/generated/client'
import { CheckUserQuery } from '@/graphql/generated/client'
/* Redirect away from these routes if not authenticated */
const protectedRoutes = ['/profile', '/search']
/* Redirect away from these routes if authenticated */
const publicRoutes = ['/login', '/register']
@nathanclevenger
nathanclevenger / github-proxy-client.js
Created February 19, 2023 19:41 — forked from DavidWells/github-proxy-client.js
Full Github REST api in 34 lines of code
/* Ultra lightweight Github REST Client */
// original inspiration via https://gist.github.com/v1vendi/75d5e5dad7a2d1ef3fcb48234e4528cb
const token = 'github-token-here'
const githubClient = generateAPI('https://api.github.com', {
headers: {
'User-Agent': 'xyz',
'Authorization': `bearer ${token}`
}
})
@stefandanaita
stefandanaita / cf-logpush-destination-worker.ts
Last active January 7, 2023 19:26
Code for a worker that can receive logpush http requests and parse the contents using streams
// SPDX-License-Identifier: MIT-0
export interface Env {
}
export default {
async fetch(
request: Request,
env: Env,
@DavidWells
DavidWells / github-proxy-client.js
Last active March 3, 2025 17:47
Full Github REST api in 34 lines of code
/* Ultra lightweight Github REST Client */
// original inspiration via https://gist.github.com/v1vendi/75d5e5dad7a2d1ef3fcb48234e4528cb
const token = 'github-token-here'
const githubClient = generateAPI('https://api.github.com', {
headers: {
'User-Agent': 'xyz',
'Authorization': `bearer ${token}`
}
})
@MichaelCurrin
MichaelCurrin / README.md
Last active July 24, 2025 13:28
Jekyll - how to build a REST API

Jekyll - how to build a REST API

Serve your data as static JSON

How to make a read-only JSON REST API using Jekyll.

This doesn't need any Ruby plugins - you just use some built-in templating features in Jekyll 3 or 4.

You will end up with a single JSON file contains data for all pages on the site, and another JSON file of just posts. Alternatively, you can replace every HTML page and post with a JSON version.

@stickfigure
stickfigure / cloak.js
Created May 24, 2020 05:42
Cloudflare worker that proxies encrypted urls
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
const encoder = new TextEncoder();
const decoder = new TextDecoder();
const SECRET_KEY_DATA = encoder.encode('YOUR SECRET KEY');
function normalizeBase64(base64urlencoded) {
return base64urlencoded.replace(/-/g, '+').replace(/_/g, '/');