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 express, { Request } from 'express'; | |
import Context from './context' | |
const app = express(); | |
// ... | |
app.get('/foo', (req: Request, res) => { | |
const ctx: Context = Context.get(req); | |
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 express, { Request } from 'express'; | |
import Context from './context' | |
const app = express(); | |
// Middleware | |
app.use((req: Request, res: any, next: any) => { | |
Context.bind(req); | |
next(); | |
}); |
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 { Request } from 'express'; | |
export default class Context { | |
static _bindings = new WeakMap<Request, Context>(); | |
public foo = 'bar'; | |
constructor () {} | |
static bind (req: Request) : void { |
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
// ... | |
app.use((req, res, next) => { | |
req.foo = 'hello world'; | |
next(); | |
}); |
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 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; | |
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 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" | |
}); |
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 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 |
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
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 |
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
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 |
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
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 |
NewerOlder