forked from techforum-repo/youttubedata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lambda-edge-functions.txt
48 lines (34 loc) · 932 Bytes
/
lambda-edge-functions.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
Node.JS
index.js
"use strict";
const config = require("./config.js");
exports.handler = (event, context, callback) => {
const cfRequest = event.Records[0].cf.request;
// Construct the auth string
const authString =
`Basic ${new Buffer(`${config.authUser}:${config.authPass}`).toString("base64")}`;
// Add auth header
if (
typeof cfRequest.headers.authorization === "undefined" ||
cfRequest.headers.authorization[0].value !== authString
) {
const response = {
status: "401",
statusDescription: "Unauthorized",
body: "Unauthorized",
headers: {
"www-authenticate": [{ key: "WWW-Authenticate", value: "Basic" }]
}
};
callback(null, response);
return;
}
// Continue request processing if authentication passed
callback(null, cfRequest);
};
config.js
"use strict";
module.exports = {
authUser: "testuser",
authPass: "testuserpass!"
};