By: @BTroncone
Also check out my lesson @ngrx/store in 10 minutes on egghead.io!
Update: Non-middleware examples have been updated to ngrx/store v2. More coming soon!
Table of Contents
| const asyncMiddleware = require('./utils/asyncMiddleware'); | |
| router.get('/users/:id', asyncMiddleware(async (req, res, next) => { | |
| /* | |
| if there is an error thrown in getUserFromDb, asyncMiddleware | |
| will pass it to next() and express will handle the error; | |
| */ | |
| const user = await getUserFromDb({ id: req.params.id }) | |
| res.json(user); | |
| })); |
| const asyncMiddleware = fn => | |
| (req, res, next) => { | |
| Promise.resolve(fn(req, res, next)) | |
| .catch(next); | |
| }; |
| beforeEach(async(() => { | |
| TestBed.configureTestingModule({ | |
| imports: [ | |
| MdToolbarModule, | |
| ], | |
| providers: [ | |
| { | |
| provide: Router, | |
| useClass: MockRouter, | |
| }, |
| import { createCipheriv, createDecipheriv, randomBytes } from "crypto"; | |
| const ENCRYPTION_KEY: string = process.env.ENCRYPTION_KEY || ""; // Must be 256 bits (32 characters) | |
| const IV_LENGTH: number = 16; // For AES, this is always 16 | |
| /** | |
| * Will generate valid encryption keys for use | |
| * Not used in the code below, but generate one and store it in ENV for your own purposes | |
| */ | |
| export function keyGen() { |
By: @BTroncone
Also check out my lesson @ngrx/store in 10 minutes on egghead.io!
Update: Non-middleware examples have been updated to ngrx/store v2. More coming soon!
Table of Contents
| function logClass(target: any) { | |
| // save a reference to the original constructor | |
| var original = target; | |
| // a utility function to generate instances of a class | |
| function construct(constructor, args) { | |
| var c : any = function () { | |
| return constructor.apply(this, args); | |
| } |
| // the main app file | |
| import express from "express"; | |
| import loadDb from "./loadDb"; // dummy middleware to load db (sets request.db) | |
| import authenticate from "./authentication"; // middleware for doing authentication | |
| import permit from "./authorization"; // middleware for checking if user's role is permitted to make request | |
| const app = express(), | |
| api = express.Router(); | |
| // first middleware will setup db connection |
| { | |
| "env": { | |
| "browser": true, | |
| "node": true, | |
| "es6": true | |
| }, | |
| "plugins": ["react"], | |
| "ecmaFeatures": { |
| .client | |
| .server | |
| Dockerfile |
| /** | |
| * example C code using libcurl and json-c | |
| * to post and return a payload using | |
| * http://jsonplaceholder.typicode.com | |
| * | |
| * License: | |
| * | |
| * This code is licensed under MIT license | |
| * https://opensource.org/licenses/MIT | |
| * |