Skip to content

Instantly share code, notes, and snippets.

@jasonbyrne
Last active January 23, 2019 02:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonbyrne/4b7b86b595aeca30ede0022909fad188 to your computer and use it in GitHub Desktop.
Save jasonbyrne/4b7b86b595aeca30ede0022909fad188 to your computer and use it in GitHub Desktop.
StackPath EdgeEngine simple auth proof of concept
import { Auth } from './auth';
addEventListener('fetch', (event: StackPathEvent) => {
event.respondWith(handleRequest(event.request));
});
async function handleRequest(request: StackPathRequest): Promise<Response> {
try {
const auth: Auth = new Auth(request);
if (!auth.isAuthenticated()) {
return new Response('Permission denied.', { status: 403 });
}
return await fetch(request);
} catch (e) {
return new Response(e.stack || e, { status: 500 });
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment