Skip to content

Instantly share code, notes, and snippets.

export const availableEndpoint =
(handler) => async (req) => {
let currentUser
try {
currentUser = await authorizeUser(req)
} catch (e) {
if (e instanceof UnauthorizedError) {
// pass!
} else {
throw e
@hovissimo
hovissimo / applyMiddleware.mjs
Last active September 22, 2022 13:28
Middleware function for Enhance.dev
/**
* applyMiddleware takes an array of middleware functions and returns a decorator that will apply
* the middleware functions in reverse order around the target function.
*
* Example
*
* const handleGet = async(req) => ({ ... })
* const mw1 = (next) => async (req) => await next(req) + " mw1"
* const mw2 = (next) => async (req) => await next(req) + " mw2"
* const mw3 = (next) => async (req) => await next(req) + " mw3"
@hovissimo
hovissimo / req
Created September 30, 2022 05:42
Enhance /foo/bar/$key.mjs
{
"version": "2.0",
"routeKey": "ANY /{proxy+}",
"rawPath": "/foo/bar/baz",
"rawQueryString": "",
"cookies": [
"_idx=eyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4R0NNIn0..YNN--0oPCWn6ChdD.AXLDL_cMMBOSRppGv2xjlppy1PkdESx3bb99IlEvKrhnJaI7I6VPniFArldGWRNldz_YNo_ilEHhchOwKk3et1C5Xnqjo4WplXv7ItyK6STOisdYfnMmEgGVFP0AUqTZNMDdpvC-c8mvsQvD0VUGeKd1ATNGZFbyDA._M1PRjCs26cccaRM0omyMw"
],
"headers": {
"host": "localhost:3333",
@hovissimo
hovissimo / aws-creds.zsh
Last active February 5, 2024 19:33 — forked from ddgenome/aws-creds.bash
Fetch AWS STS keys and set environment variables
#!/bin/zsh
# Fetch 24-hour AWS STS session token and set appropriate environment variables.
# See http://docs.aws.amazon.com/cli/latest/reference/sts/get-session-token.html .
# You must have jq installed and in your PATH https://stedolan.github.io/jq/ .
# Add this function to your .bashrc or save it to a file and source that file from .bashrc .
# Online: https://gist.github.com/hovissimo/c9119820a5a4f5a6081d93f87f1688b4
# Adapted from https://gist.github.com/ddgenome/f13f15dd01fb88538dd6fac8c7e73f8c
#
# usage: aws-creds AWS_PROFILE MFA_TOKEN [OTHER_AWS_STS_GET-SESSION-TOKEN_OPTIONS...]
# example: aws-creds staging 123456
##
# Hello hello!
#
# This is meant to be a quick (and fun?) sense-check of your Ruby!
#
# Notes:
# 0. How are you today? 👋
# 1. Feel free to download the CSV locally, paste lines of this file into irb, or run this with `ruby requests.rb`!
# 2. We're loosely available to field questions on the email thread (or via [email protected])
# 3. Don't overanalyze your implementation/formatting/variable names/etc. do what comes naturally to you