This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Router } from 'https://pkg.do/itty-router' | |
import { withParams, json } from 'https://pkg.do/itty-router-extras' | |
const router = Router() | |
router.get('/', ({url}) => json({ url, 'Deploy your Gist 🚀': 'https://gist.do/6879562075da644e51a09440f30970da' })) | |
export default { | |
fetch: router.handle | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default api = (number = 5) => ({ number, squared: number^2, cubed: number^3 }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default api = (number = 5) => { number, squared: number^2, cubed: number^3 }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { apis, json } from 'https://pkg.do/apis.do' | |
export default { | |
fetch: () => json({apis}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { api } from 'https://pkg.do/apis.do' | |
const myAPI = api(number = 5 => { number, squared: number^2, cubed: number^3 }) | |
export default myAPI |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const config :Workerd.Config = ( | |
services = [ | |
(name = "site-worker", worker = .siteWorker), | |
], | |
sockets = [ | |
(name = "https", address = "*:443", https = (tlsOptions = .tlsOptions), service = "site-worker") | |
], | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default obj => new Response(JSON.stringify(obj, null, 2)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import type { Jsonify } from "type-fest"; | |
// Define new storage types here and below and the storage below will automatically use them. | |
// prettier-ignore | |
type TypedDurableObjectStorageValue<Key extends string> = Jsonify< | |
| Key extends "simple" ? boolean : never | |
| Key extends "complex" ? { age: number } | { name: string } : never | |
| Key extends `template:type:known` ? number : never | |
| Key extends `template:type:${string}` ? string | number : never | |
>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// function replacer(key, value) { | |
// if(value instanceof Map) { | |
// return { | |
// dataType: 'Map', | |
// value: Array.from(value.entries()), // or with spread: value: [...value] | |
// }; | |
// } else { | |
// return value; | |
// } | |
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, '/'); |