Skip to content

Instantly share code, notes, and snippets.

View justinnoel's full-sized avatar

Justin Noel justinnoel

View GitHub Profile
@justinnoel
justinnoel / package.json
Last active December 19, 2023 13:47
Hono Tailwind for Dev and Production
{
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build && vite build --mode client && npx tailwindcss -i ./src/index.css -o ./dist/static/assets/index.css --minify",
"format": "prettier --config .prettierrc --ignore-path .prettierignore '**/*.{json,js,jsx,ts,tsx,css,scss,md}' --write",
"lint": "eslint --ext \".js,.jsx,.ts,.tsx\" --ignore-path .eslintignore . --max-warnings 0 --fix",
"prepare": "husky install"
},
"husky": {
@justinnoel
justinnoel / log-remote.ts
Last active June 13, 2023 22:42
Send logs to external service in a Cloudflare Remix project
type LogRemote = {
details: {
message: string,
},
env: {
REMOTE_LOGGING_URL: string,
REMOTE_LOGGING_KEY: string,
REMOTE_LOGGING_SOURCE: string,
},
};
@justinnoel
justinnoel / App.tsx
Created December 9, 2022 16:57
Jason Workout App
<Register history={props.history} />
@justinnoel
justinnoel / README.md
Created November 12, 2022 12:34
Configuring Sessions in Remix for Cloudflare Pages
@justinnoel
justinnoel / zeptomail_3.0.2_modifications.js
Created September 9, 2022 17:06
ZeptoMail JS Client 3.0.2 Issues
import fetch from 'node-fetch';
function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
if (enumerableOnly) {
symbols = symbols.filter(function (sym) {
@justinnoel
justinnoel / cf-worker.js
Created June 20, 2022 17:53
Example of very simple API used while learning front-end development
addEventListener("fetch", (event) => {
event.respondWith(handleRequest(event.request));
});
const workouts = [
{
week: 1,
starts: 18383383383,
workout: [
{
@justinnoel
justinnoel / sample-cloudflare-worker-post-processor.js
Last active April 22, 2022 19:42
A Cloudflare Worker to extract POST data submitted as either JSON or as a form.
addEventListener("fetch", (event) => {
event.respondWith(handleRequest(event.request).catch((err) => new Response(err.stack, {status: 500})));
});
async function handleRequest(request) {
const {pathname} = new URL(request.url);
if (pathname.startsWith("/api/post")) {
const {data, error} = await getPostData(request);
if (error) {
return new Response(error, {status: 400})
@justinnoel
justinnoel / getPostData.js
Created January 29, 2022 15:19
Get POST data submitted as either JSON or FormData
export async function getPostData(request) {
const {headers} = request;
const contentType = headers.get("content-type") || "";
if (contentType.includes("application/json")) {
return await request.json();
}
if (contentType.includes("form")) {
const formData = await request.formData();
@justinnoel
justinnoel / gist:74f28a203672b66aaee80629991f5edb
Created December 14, 2021 19:45 — forked from cryptoskillz/gist:98b8e7090b7cc8d51531bb9dcfe7654a
Tips on how to use a KV namespace with Cloudflare Pages
This gist aims to show you how to use KV datastore using Cloudflare pages. The reason I created this quick guide is it took
me almost 2 weeks to get it working, mainly because it is very new and the documentation is not up fully fleshed out yet
https://developers.cloudflare.com/workers/runtime-apis/kv
https://developers.cloudflare.com/pages/platform/functions
https://blog.cloudflare.com/wrangler-v2-beta/
Steps:
Install wrangler 2
@justinnoel
justinnoel / getJson.js
Last active November 13, 2021 12:54
Helper function to get JSON data from an API call and handle failures.
export async function getJson(url, options) {
try {
const response = await fetch(url, options);
const contentType = response.headers.get("content-type");
if (! response.ok || ! contentType.includes("application/json")) {
console.log(`ERROR: getJSON -> Invalid Response -> response.status = ${
response.status
}`,);
console.log(`ERROR: getJSON -> Invalid Response ->response.statusText = ${