Skip to content

Commit 1468009

Browse files
committed
Add comments to LD API handler files
1 parent c389dd0 commit 1468009

3 files changed

Lines changed: 6 additions & 4 deletions

File tree

api/getLinkedData.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const metascraper = require('metascraper')([
88
require('metascraper-image')()
99
]);
1010

11+
// Specify origins allowed to access this function
1112
const allowedOrigin = (process.env.NODE_ENV == "development") ? "http://localhost:3333" : "https://cms.uxmethods.org";
1213

1314
module.exports = async (req, res, next) => {
@@ -19,12 +20,12 @@ module.exports = async (req, res, next) => {
1920
const targetUrl = response.link;
2021
const { body: html, url } = await got(targetUrl);
2122
const metadata = await metascraper({ html, url });
22-
res.locals.resourceData = metadata;
23-
next();
23+
res.locals.resourceData = metadata; // writes metadata to a local object to pass to the next handler
24+
next(); // pass control to the next handler
2425
} catch (e) {
2526
console.error(e);
2627
}
27-
} else {
28+
} else { // Boot out any origins not on my allowed list.
2829
console.log("Unauthorized origin. Originating URL is: " + requestOrigin);
2930
res.status(401).end('Unauthorized origin.');
3031
}

api/postImage.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const client = sanityClient({
99
projectId: projectId,
1010
dataset: 'production',
1111
apiVersion: '2021-03-25',
12+
useCdn: true,
1213
token: uxmToken
1314
});
1415

api/postLinkedData.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = async (req, res, next) => {
1616
patch: {
1717
id: resourceId,
1818
set: {
19-
title: metadata.title != null ? metadata.title : "",
19+
title: metadata.title != null ? metadata.title : "",
2020
author: metadata.author != null ? metadata.author : "",
2121
publisher: {
2222
pubName: metadata.publisher != null ? metadata.publisher : "",

0 commit comments

Comments
 (0)