Skip to content

Instantly share code, notes, and snippets.

View jasonbyrne's full-sized avatar

Jason Byrne jasonbyrne

View GitHub Profile
@jasonbyrne
jasonbyrne / persist-me.js
Created December 21, 2018 05:47
Proof of Concept: Persistent Data with Lambda
let counter = 0;
exports.handler = async (event) => {
counter++;
return {
statusCode: 200,
body: JSON.stringify(counter),
};
};
@jasonbyrne
jasonbyrne / index.js
Created January 3, 2019 20:41
HLS Checker Lambda - Loads an HLS playlist and then all of the underlying chunklists and segments to make sure all of the files exist and basic validity checks.
const HLS = require('hls-parser');
const request = require('request');
const URL = require('url').URL
// Error codes
const ERROR = {
INVALID_PLAYLIST_URL: {
code: 100,
message: 'Invalid playlist URL'
},
@jasonbyrne
jasonbyrne / index.ts
Last active January 23, 2019 02:05
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()) {
@jasonbyrne
jasonbyrne / package.json
Last active March 19, 2019 15:34
Firebase Functions Example
{
"name": "functions",
"scripts": {
"lint": "tslint --project tsconfig.json",
"build": "tsc",
"serve": "npm run build && firebase serve --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
@jasonbyrne
jasonbyrne / flagpole-demo-test.js
Created August 15, 2019 21:43
Sample Test Suite created in the Flagpole Walkthrough on August 15, 2019
const { Flagpole } = require('flagpole');
const searchTerm = 'Flagpole QA';
const suite = Flagpole.suite('Basic Smoke Test of Site')
.base('https://www.google.com');
suite.html('Homepage Loads')
.open('/')
.next('Test the basic headers', (ctx) => {
@jasonbyrne
jasonbyrne / npmjs.js
Created September 5, 2019 05:34
Flagpole suite with Puppeteer
const { Flagpole } = require('flagpole');
const opts = {
headless: false,
width: 1280,
height: 600
};
const suite = Flagpole.suite('Basic Smoke Test of npmjs.com')
.base('https://www.npmjs.com/');
@jasonbyrne
jasonbyrne / index.ts
Created April 27, 2020 13:07
Simplest CDN Worker
function handleRequest(request: Request): Promise<Response> {
return fetch(request);
}
addEventListener('fetch', (event) => {
event.respondWith(handleRequest(event.request))
});
@jasonbyrne
jasonbyrne / lambda.js
Created April 27, 2020 13:12
Lambda@Edge Simplest Example
'use strict';
exports.handler = (event, context, callback) => {
const request = event.Records[0].cf.request;
return callback(null, request);
};
@jasonbyrne
jasonbyrne / custom-header2.ts
Created April 27, 2020 13:26
Add custom header at edge that works on StackPath and Cloudflare
export async function addCustomHeader(response: Response): Promise<Response> {
const modifiedResponse = new Response(await response.arrayBuffer(), response);
modifiedResponse.headers.set("X-My-Custom-Header", "Hello there!");
return modifiedResponse;
}
@jasonbyrne
jasonbyrne / custom-header.ts
Last active April 27, 2020 13:26
Cloudflare Worker to add a header
export async function addCustomHeader(response: Response): Promise<Response> {
const modifiedResponse = new Response(response.body, response);
modifiedResponse.headers.set("X-My-Custom-Header", "Hello there!");
return modifiedResponse;
}