Skip to content

Commit af783f4

Browse files
process-url
1 parent 57087e4 commit af783f4

File tree

4 files changed

+71
-1
lines changed

4 files changed

+71
-1
lines changed

Diff for: Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
install:
2-
cd functions/gen-opengraph-image && npm i && npm run build
2+
cd functions/gen-opengraph-image && npm i && npm run build
3+
cd functions/process-url && npm i

Diff for: functions/process-url/package.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "process-url",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"author": "christopherbiscardi <[email protected]> (@chrisbiscardi)",
6+
"license": "MIT",
7+
"dependencies": {
8+
"cloudinary": "^1.20.0"
9+
}
10+
}

Diff for: functions/process-url/process-url.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const cloudinary = require("cloudinary").v2;
2+
const qs = require("querystring");
3+
cloudinary.config({
4+
cloud_name: "sector",
5+
api_key: process.env.CLOUDINARY_KEY,
6+
api_secret: process.env.CLOUDINARY_SECRET
7+
});
8+
9+
exports.handler = async function(event, ctx) {
10+
const { queryStringParameters } = event;
11+
12+
try {
13+
// https://res.cloudinary.com/sector/image/upload/v1583637123/og-images/img-1.png
14+
const imageUrl = cloudinary.url(
15+
`${process.env.CHRIS_IMAGE_VERSION}/og-images/img-1.png`,
16+
{
17+
// resouce_type: "raw"
18+
sign_url: true,
19+
// secure: true,
20+
custom_pre_function: {
21+
function_type: "remote",
22+
source: `https://relaxed-payne-d1bfbe.netlify.com/.netlify/functions/gen-opengraph-image?${qs.stringify(
23+
queryStringParameters
24+
)}`
25+
}
26+
}
27+
);
28+
return {
29+
statusCode: 302,
30+
headers: {
31+
Location: imageUrl
32+
},
33+
body: ""
34+
};
35+
} catch (e) {
36+
console.log(e);
37+
}
38+
};

Diff for: functions/process-url/yarn.lock

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
cloudinary@^1.20.0:
6+
version "1.20.0"
7+
resolved "https://registry.yarnpkg.com/cloudinary/-/cloudinary-1.20.0.tgz#88f3964be91cc9808b5c7834bf06e03d22954636"
8+
integrity sha512-/e76lEr5PS5gefvWUJ2Ou90zuEQCc0agTq8hrx2uxfFhUGlzEQ9mPPcwAeHFY1gj9caq0iHLuvTDvBbLSRhX9w==
9+
dependencies:
10+
lodash "^4.17.11"
11+
q "^1.5.1"
12+
13+
lodash@^4.17.11:
14+
version "4.17.15"
15+
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548"
16+
integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==
17+
18+
q@^1.5.1:
19+
version "1.5.1"
20+
resolved "https://registry.yarnpkg.com/q/-/q-1.5.1.tgz#7e32f75b41381291d04611f1bf14109ac00651d7"
21+
integrity sha1-fjL3W0E4EpHQRhHxvxQQmsAGUdc=

0 commit comments

Comments
 (0)