Skip to content

Instantly share code, notes, and snippets.

View ernestofreyreg's full-sized avatar
🚢
Just ship it

Ernesto Freyre ernestofreyreg

🚢
Just ship it
View GitHub Profile
import typescript from 'rollup-plugin-typescript2'
import commonjs from 'rollup-plugin-commonjs'
import external from 'rollup-plugin-peer-deps-external'
import resolve from 'rollup-plugin-node-resolve'
import pkg from './package.json'
export default {
input: 'src/index.ts',
output: [
{
"compilerOptions": {
"outDir": "build",
"module": "esnext",
"target": "esnext",
"lib": ["esnext", "webworker"],
"sourceMap": false,
"allowJs": false,
"importHelpers": false,
"declaration": false,
function handler (event: FetchEvent) {
event.respondWith(new Response(JSON.stringify({ hello: 'worker' }), { status: 200 }))
}
addEventListener('fetch', handler)
import { KVNamespace } from '@cloudflare/workers-types'
declare const TODOS: KVNamespace
async function handleGETRequests (request: Request) {
const url = new URL(request.url)
switch (url.pathname) {
case '/status':
return new Response(JSON.stringify({ hello: 'world' }))
export interface ValidateJWT {
valid: boolean
payload?: any
}
export async function isValidJwt (request: Request): Promise<ValidateJWT> {
const encodedToken = getJwt(request)
if (encodedToken === null) {
return { valid: false }
}
import { isValidJwt } from './jwt'
import { KVNamespace } from '@cloudflare/workers-types'
declare const TODOS: KVNamespace
async function handleGETRequests (request: Request, token: any) {
const url = new URL(request.url)
switch (url.pathname) {
case '/status':
return new Response(JSON.stringify({ hello: 'world' }))
export function handleOptions (request: Request) {
if (
request.headers.get('Origin') !== null &&
request.headers.get('Access-Control-Request-Method') !== null &&
request.headers.get('Access-Control-Request-Headers') !== null
) {
return new Response(null, {
headers: corsHeaders
})
} else {
import { isValidJwt } from './jwt'
import { corsHeaders, handleOptions } from './cors'
import { KVNamespace } from '@cloudflare/workers-types'
declare const TODOS: KVNamespace
const withStatus = (status: number = 200, headers?: any) => ({
status,
headers: { ...corsHeaders, ...(headers || {}) }
})
const pwhile = function (condition, action) {
const loop = function (promise) {
if (!condition()) {
return promise
}
return promise
.then(action)
.then(() => loop(promise))
.catch(promise.reject)
import * as React from 'react'
import { render } from '@testing-library/react'
const DemoContext = React.createContext<any>(null)
describe('Demo', () => {
const setup = DummyComponent => {
const update = jest.fn()
const utils = render(
<DemoContext.Provider value={{ update }}>