This file contains hidden or 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 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: [ |
This file contains hidden or 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
Show hidden characters
{ | |
"compilerOptions": { | |
"outDir": "build", | |
"module": "esnext", | |
"target": "esnext", | |
"lib": ["esnext", "webworker"], | |
"sourceMap": false, | |
"allowJs": false, | |
"importHelpers": false, | |
"declaration": false, |
This file contains hidden or 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 handler (event: FetchEvent) { | |
event.respondWith(new Response(JSON.stringify({ hello: 'worker' }), { status: 200 })) | |
} | |
addEventListener('fetch', handler) |
This file contains hidden or 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 { 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' })) |
This file contains hidden or 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 interface ValidateJWT { | |
valid: boolean | |
payload?: any | |
} | |
export async function isValidJwt (request: Request): Promise<ValidateJWT> { | |
const encodedToken = getJwt(request) | |
if (encodedToken === null) { | |
return { valid: false } | |
} |
This file contains hidden or 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 { 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' })) |
This file contains hidden or 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 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 { |
This file contains hidden or 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 { 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 || {}) } | |
}) |
This file contains hidden or 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 pwhile = function (condition, action) { | |
const loop = function (promise) { | |
if (!condition()) { | |
return promise | |
} | |
return promise | |
.then(action) | |
.then(() => loop(promise)) | |
.catch(promise.reject) |
This file contains hidden or 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 * 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 }}> |