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
export async function personalizeBody( | |
response: Response, | |
request: Request | |
): Promise<Response> { | |
const originalBody = await response.text(); | |
const newBody = originalBody.replace( | |
/{{ timestamp }}/g, | |
new Date().toUTCString() | |
); | |
const modifiedResponse = new Response(newBody, response); |
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
const hosts = { | |
cloudFlare: "https://flosports-video.s3.amazon.com", | |
stackPath: "https://cdn.stackpath.flosports.tv", | |
}; | |
function isStackPath(request: Request): boolean { | |
const url = new URL(request.url); | |
return !!url.hostname.match(/stackpath/); | |
} |
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 flagpole from "flagpole"; | |
import * as ngrok from "ngrok"; | |
flagpole("Just a basic webhook callback", async (suite) => { | |
// Create webhook scenario | |
const webhook = await suite | |
.scenario("Wait for a webhook", "resource") | |
.webhook("GET /foo") | |
.next(async (context) => { | |
context.comment("Webhook was hit!"); |
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 { Injectable } from '@angular/core'; | |
@Injectable({ | |
providedIn: 'root', | |
}) | |
export class PubSub { | |
private topics: { [id: string]: PubSubTopic } = {}; | |
private constructor() {} |
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
/** | |
* Summernote PasteClean | |
* | |
* This is a plugin for Summernote (www.summernote.org) WYSIWYG editor. | |
* It will clean up the content your editors may paste in for unknown sources | |
* into your CMS. It strips Word special characters, style attributes, script | |
* tags, and other annoyances so that the content can be clean HTML with | |
* no unknown hitchhiking scripts or styles. | |
* | |
* @author Jason Byrne, FloSports <jason.byrne@flosports.tv> |
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
addEventListener('fetch', event => event.respondWith(handleRequest(event))); | |
async function handleRequest(event) { | |
const request = event.request; | |
// Parse query string | |
const { searchParams } = new URL(request.url); | |
let qsName = searchParams.get('name'); | |
// If name in query string, add it to kv async | |
if (qsName) { | |
// Run this async to response, but wait for it to complete before terminating |
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 { Router } from "./helpers/router"; | |
import { getQueryString } from "./helpers/querystring"; | |
const MAGIC_WORD = "flo"; | |
function catchAll(request: Request): Response { | |
return fetch(request.url, request); | |
} | |
function validateTokenThenFetch( |
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
/* Firebase Functions messes with your request and will wreck your day because none of the | |
* traditional upload handlers with Express will work. | |
* | |
* Credit: https://stackoverflow.com/questions/47242340/how-to-perform-an-http-file-upload-using-express-on-cloud-functions-for-firebase | |
*/ | |
const Busboy = require('busboy'); | |
const allowedMethods: string[] = ['POST', 'PUT']; | |
export class FileUpload { |
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 { ExceptionFilter, Catch, ArgumentsHost } from '@nestjs/common'; | |
import { Response } from 'express'; | |
import { IncomingMessage } from 'http'; | |
import { HttpException, HttpStatus } from '@nestjs/common'; | |
export const getStatusCode = (exception: unknown): number => { | |
return exception instanceof HttpException | |
? exception.getStatus() | |
: HttpStatus.INTERNAL_SERVER_ERROR; | |
}; |
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 { NestFactory } from '@nestjs/core'; | |
import { AppModule } from './app.module'; | |
import { GlobalExceptionFilter } from './exception-handler'; | |
async function bootstrap() { | |
const app = await NestFactory.create(AppModule); | |
app.useGlobalFilters(new GlobalExceptionFilter()); | |
await app.listen(3000); | |
} | |
bootstrap(); |