Last active
January 23, 2019 02:05
-
-
Save jasonbyrne/4b7b86b595aeca30ede0022909fad188 to your computer and use it in GitHub Desktop.
StackPath EdgeEngine simple auth proof of concept
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 { 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