Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Considering new contract opportunities at this time

Andrew E. Rhyne thebigredgeek

💭
Considering new contract opportunities at this time
View GitHub Profile
View route-controller.ts
import express, { Request } from 'express';
import Context from './context'
const app = express();
// ...
app.get('/foo', (req: Request, res) => {
const ctx: Context = Context.get(req);
@thebigredgeek
thebigredgeek / middleware.ts
Created Sep 9, 2020
Context Middleware for Express
View middleware.ts
import express, { Request } from 'express';
import Context from './context'
const app = express();
// Middleware
app.use((req: Request, res: any, next: any) => {
Context.bind(req);
next();
});
@thebigredgeek
thebigredgeek / contextclass.ts
Last active Sep 9, 2020
Context Class for Requests
View contextclass.ts
import { Request } from 'express';
export default class Context {
static _bindings = new WeakMap<Request, Context>();
public foo = 'bar';
constructor () {}
static bind (req: Request) : void {
@thebigredgeek
thebigredgeek / middleware.js
Created Sep 9, 2020
Express req decoration
View middleware.js
// ...
app.use((req, res, next) => {
req.foo = 'hello world';
next();
});
@thebigredgeek
thebigredgeek / example.js
Created May 19, 2020
JWT Tenant Secret Middleware
View example.js
const model = require('./model'); // our fake model
const verifyJWT = async (req, res, next) => {
// Extract the authorization header
const header = req.get('Authorization');
let err
, secret
, id;
@thebigredgeek
thebigredgeek / endpoint.js
Last active May 18, 2020
JWT Protected Endpoint
View endpoint.js
const verifyJWT = async (req, res, next) => {
// Extract the authorization header
const header = req.get('Authorization');
// If no authorization header is present,
// send back an error
if (!header) {
res.status(401).send({
message: "Authorization required"
});
@thebigredgeek
thebigredgeek / login.js
Last active May 19, 2020
JWT Login Example
View login.js
const express = require('express')
, { json } = require('body-parser')
, jwt = require('jsonwebtoken')
, to = require('await-to-js')
, model = require('./model'); // fake model
// This only lives on the server, never the client!
const JWT_SECRET = process.env.JWT_SECRET;
// create a server instance
@thebigredgeek
thebigredgeek / netlify.log
Created Mar 24, 2020
netlify failed deploy
View netlify.log
3:57:02 PM: Build ready to start
3:57:04 PM: build-image version: 2dbd444fcdce00cf06325060a8238d5ae3e86774
3:57:04 PM: build-image tag: v3.3.7
3:57:04 PM: buildbot version: 11918e084194721d200458438c92ff8180b3b56c
3:57:05 PM: Fetching cached dependencies
3:57:05 PM: Starting to download cache of 254.9KB
3:57:05 PM: Finished downloading cache in 164.787524ms
3:57:05 PM: Starting to extract cache
3:57:05 PM: Failed to fetch cache, continuing with build
3:57:05 PM: Starting to prepare the repo for build
@thebigredgeek
thebigredgeek / netlify.log
Created Mar 24, 2020
netlify failed deploy
View netlify.log
3:57:02 PM: Build ready to start
3:57:04 PM: build-image version: 2dbd444fcdce00cf06325060a8238d5ae3e86774
3:57:04 PM: build-image tag: v3.3.7
3:57:04 PM: buildbot version: 11918e084194721d200458438c92ff8180b3b56c
3:57:05 PM: Fetching cached dependencies
3:57:05 PM: Starting to download cache of 254.9KB
3:57:05 PM: Finished downloading cache in 164.787524ms
3:57:05 PM: Starting to extract cache
3:57:05 PM: Failed to fetch cache, continuing with build
3:57:05 PM: Starting to prepare the repo for build
@thebigredgeek
thebigredgeek / netlify.log
Created Mar 24, 2020
netlify failed deploy
View netlify.log
3:57:02 PM: Build ready to start
3:57:04 PM: build-image version: 2dbd444fcdce00cf06325060a8238d5ae3e86774
3:57:04 PM: build-image tag: v3.3.7
3:57:04 PM: buildbot version: 11918e084194721d200458438c92ff8180b3b56c
3:57:05 PM: Fetching cached dependencies
3:57:05 PM: Starting to download cache of 254.9KB
3:57:05 PM: Finished downloading cache in 164.787524ms
3:57:05 PM: Starting to extract cache
3:57:05 PM: Failed to fetch cache, continuing with build
3:57:05 PM: Starting to prepare the repo for build