Skip to content

Instantly share code, notes, and snippets.

View rishi-raj-jain's full-sized avatar
☺️

Rishi Raj Jain rishi-raj-jain

☺️
View GitHub Profile
@rishi-raj-jain
rishi-raj-jain / index.ts
Last active November 18, 2024 03:37
Google OAuth 2.0 on the Edge with Hono and Cloudflare Workers
// Do enable nodejs_compat
// https://developers.cloudflare.com/workers/runtime-apis/nodejs/
import crypto from 'node:crypto'
import { Context, Hono } from 'hono'
const app = new Hono()
function generateJWT(payload, secret, expiresIn) {
const header = { alg: 'HS256', typ: 'JWT' }
const encodedHeader = base64UrlEncode(JSON.stringify(header))
const fs = require("fs");
const path = require("path");
const https = require("https");
var ImageKit = require("imagekit");
const projectId = "";
var imagekit = new ImageKit({
publicKey: "",
privateKey: "",
import os, re, requests, shutil, asyncio, time, aiohttp
root = next(os.walk('.'))[1]
root.remove('.git')
pattern = r'https?://(?:[^\s()<>{}\[\]]+\.(?:jpg|jpeg|gif|png))(?![^\s]*\))'
async def get(url, session):
try:
async with session.get(url=url) as response:
const { data } = require("./data");
const StoryblokClient = require("storyblok-js-client");
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
const Storyblok = new StoryblokClient({
oauthToken: "",
});
const spaceId = 164462;
// This file was added by layer0 init.
// You should commit this file to source control.
require('dotenv').config()
const { Router, CustomCacheKey } = require('@layer0/core/router')
const { nuxtRoutes } = require('@layer0/nuxt')
const homeRedirect = require('./faas/home-redirect.js')
const clearCache = require('./faas/clear-cache.js')
const sitemap = require('./faas/sitemap.js')
<script>
// Check that service workers are supported
if ('serviceWorker' in navigator) {
// Use the window load event to keep the page load performant
window.addEventListener('load', () => {
navigator.serviceWorker.register('/service-worker.js');
});
}
</script>
npx workbox-cli injectManifest && node compile_sw.js
const { build } = require("esbuild")
build({
entryPoints: ["./path/to/service-worker.js"],
outfile: "./dist/service-worker.js",
minify: true,
bundle: true,
define: {
'process.env.NODE_ENV': '"production"',
'process.env.SOME_VARIABLE': '"SOME_VALUE"'
module.exports = {
globDirectory: "dist/",
globPatterns: [
"**/*.{css,eot,html,ico,jpg,js,json,png,svg,ttf,txt,webmanifest,woff,woff2,webm,xml}",
],
globFollow: true,
globStrict: true,
globIgnores: [
"**/*-es5.*.js",
"3rdpartylicenses.txt",
const express = require('express')
const app = express()
app.use(express.json())
app.all('/api/some-route/:slug.json', (req, res) => {
const slug = req.params.slug
// some data fetching calls from the slug
res.json({ data: 'data' })
})