Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inject clientContext to served function on dev-server #57

Merged
merged 2 commits into from
Jan 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion lib/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var expressLogging = require("express-logging");
var queryString = require("querystring");
var path = require("path");
var conf = require("./config");
var jwtDecode = require("jwt-decode")

function handleErr(err, response) {
response.statusCode = 500;
Expand Down Expand Up @@ -76,7 +77,17 @@ function createHandler(dir, static) {
};

var callback = createCallback(response);
var promise = handler.handler(lambdaRequest, {}, callback);
let clientContext = {}
if (request.headers['authorization']) {
const parts = request.headers['authorization'].split(' ')
if (parts.length === 2 && parts[0] === 'Bearer') {
clientContext = {
identity: { url: '', token: '' },
user: jwtDecode(parts[1])
}
}
}
var promise = handler.handler(lambdaRequest, { clientContext }, callback);
promiseCallback(promise, callback);
};
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"commander": "^2.17.1",
"express": "^4.16.3",
"express-logging": "^1.1.1",
"jwt-decode": "^2.2.0",
"toml": "^2.3.3",
"webpack": "^4.17.1",
"webpack-merge": "^4.1.4"
Expand Down
17 changes: 17 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2040,6 +2040,23 @@ json5@^0.5.0:
version "0.5.1"
resolved "https://registry.yarnpkg.com/json5/-/json5-0.5.1.tgz#1eade7acc012034ad84e2396767ead9fa5495821"

jsonify@~0.0.0:
version "0.0.0"
resolved "https://registry.yarnpkg.com/jsonify/-/jsonify-0.0.0.tgz#2c74b6ee41d93ca51b7b5aaee8f503631d252a73"

jsprim@^1.2.2:
version "1.4.1"
resolved "https://registry.yarnpkg.com/jsprim/-/jsprim-1.4.1.tgz#313e66bc1e5cc06e438bc1b7499c2e5c56acb6a2"
dependencies:
assert-plus "1.0.0"
extsprintf "1.3.0"
json-schema "0.2.3"
verror "1.10.0"

jwt-decode@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/jwt-decode/-/jwt-decode-2.2.0.tgz#7d86bd56679f58ce6a84704a657dd392bba81a79"

kind-of@^3.0.2, kind-of@^3.0.3, kind-of@^3.2.0:
version "3.2.2"
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-3.2.2.tgz#31ea21a734bab9bbb0f32466d893aea51e4a3c64"
Expand Down