From 7532c20348c2568b9fcf0e4c3c872838f7d50da7 Mon Sep 17 00:00:00 2001 From: Tom Steele Date: Thu, 26 Apr 2018 00:56:14 -0600 Subject: [PATCH] Adds a proxy hook request example in node --- examples/proxy_request_hook/index.js | 38 ++++++++++++++++++++++++++++ gradlew | 26 ++++++++++++------- gradlew.bat | 6 ----- 3 files changed, 55 insertions(+), 15 deletions(-) create mode 100644 examples/proxy_request_hook/index.js diff --git a/examples/proxy_request_hook/index.js b/examples/proxy_request_hook/index.js new file mode 100644 index 0000000..e690581 --- /dev/null +++ b/examples/proxy_request_hook/index.js @@ -0,0 +1,38 @@ +'use strict'; + +const Hapi = require('hapi'); + +const server = Hapi.server({ + port: 3001, + host: 'localhost' +}); + +server.route({ + method: 'POST', + path: '/request', + handler: (request, reply) => { + request.payload.request.method = 'DELETE'; + console.log(request.payload); + return request.payload; + } +}); + +server.route({ + method: 'DELETE', + path: '/testme', + handler: (request, reply) => { + return 'woo'; + } +}); + +const init = async () => { + await server.start(); + console.log(`Server running at ${server.info.uri}`); +}; + +process.on('unhandledRejection', (err) => { + console.log(err); + process.exit(); +}); + +init(); \ No newline at end of file diff --git a/gradlew b/gradlew index 27309d9..cccdd3d 100644 --- a/gradlew +++ b/gradlew @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh ############################################################################## ## @@ -33,11 +33,11 @@ DEFAULT_JVM_OPTS="" # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" -warn ( ) { +warn () { echo "$*" } -die ( ) { +die () { echo echo "$*" echo @@ -154,11 +154,19 @@ if $cygwin ; then esac fi -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " } -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" +APP_ARGS=$(save "$@") -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index 832fdb6..f955316 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -49,7 +49,6 @@ goto fail @rem Get command-line arguments, handling Windows variants if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_args :win9xME_args @rem Slurp the command line arguments. @@ -60,11 +59,6 @@ set _SKIP=2 if "x%~1" == "x" goto execute set CMD_LINE_ARGS=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -set CMD_LINE_ARGS=%$ :execute @rem Setup the command line