diff --git a/client/netlify/edge-functions/og-metadata.js b/client/netlify/edge-functions/og-metadata.js
index 85d45e02..530b7e89 100644
--- a/client/netlify/edge-functions/og-metadata.js
+++ b/client/netlify/edge-functions/og-metadata.js
@@ -166,59 +166,59 @@ export default async (request, context) => {
// Replace page title
modifiedHtml = modifiedHtml.replace(
- /
[^<]*<\/title>/,
+ /[^<]*<\/title>/i,
`${escapeHtml(ogTitle)}`
);
// Replace meta description
modifiedHtml = modifiedHtml.replace(
- //,
+ /]*name=["']?description["']?[^>]*>/i,
``
);
// Replace og:title
modifiedHtml = modifiedHtml.replace(
- //,
+ /]*property=["']?og:title["']?[^>]*>/i,
``
);
// Replace og:description
modifiedHtml = modifiedHtml.replace(
- //,
+ /]*property=["']?og:description["']?[^>]*>/i,
``
);
// Replace og:image
modifiedHtml = modifiedHtml.replace(
- //,
+ /]*property=["']?og:image["']?[^>]*>/i,
``
);
// Replace og:url
modifiedHtml = modifiedHtml.replace(
- //,
+ /]*property=["']?og:url["']?[^>]*>/i,
``
);
// Replace og:type to "article" for quote pages
modifiedHtml = modifiedHtml.replace(
- //,
+ /]*property=["']?og:type["']?[^>]*>/i,
``
);
// Replace Twitter card metadata
modifiedHtml = modifiedHtml.replace(
- //,
+ /]*name=["']?twitter:title["']?[^>]*>/i,
``
);
modifiedHtml = modifiedHtml.replace(
- //,
+ /]*name=["']?twitter:description["']?[^>]*>/i,
``
);
modifiedHtml = modifiedHtml.replace(
- //,
+ /]*name=["']?twitter:image["']?[^>]*>/i,
``
);
diff --git a/server/app/data/resolvers/queries/post/getPost.js b/server/app/data/resolvers/queries/post/getPost.js
index 718224b6..5f1f1867 100644
--- a/server/app/data/resolvers/queries/post/getPost.js
+++ b/server/app/data/resolvers/queries/post/getPost.js
@@ -1,8 +1,18 @@
+import mongoose from 'mongoose';
import PostModel from '../../models/PostModel';
export const getPost = (pubsub) => {
return async (_, args, context) => {
- const post = await PostModel.findById(args.postId);
+ let post;
+
+ // Check if the provided postId is a valid MongoDB ObjectId
+ if (mongoose.Types.ObjectId.isValid(args.postId)) {
+ post = await PostModel.findById(args.postId);
+ } else {
+ // If it's not a valid ObjectId, assume it's a short URL ID (urlId)
+ post = await PostModel.findOne({ urlId: args.postId });
+ }
+
if (!post || post.deleted) {
if (context && context.res) {
context.res.status(404);
diff --git a/test_fetch.js b/test_fetch.js
new file mode 100644
index 00000000..08a882aa
--- /dev/null
+++ b/test_fetch.js
@@ -0,0 +1,26 @@
+const postId = "e_6A4M";
+const graphqlUrl = 'https://api.quote.vote/graphql';
+const graphqlQuery = {
+ query: `
+ query post($postId: String!) {
+ post(postId: $postId) {
+ _id
+ title
+ text
+ url
+ creator {
+ name
+ avatar
+ }
+ }
+ }
+ `,
+ variables: { postId },
+};
+fetch(graphqlUrl, {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify(graphqlQuery),
+}).then(res => res.json()).then(data => console.log(JSON.stringify(data, null, 2))).catch(err => console.error(err));
diff --git a/test_get_posts.js b/test_get_posts.js
new file mode 100644
index 00000000..d39b5327
--- /dev/null
+++ b/test_get_posts.js
@@ -0,0 +1,9 @@
+const graphqlUrl = 'https://api.quote.vote/graphql';
+fetch(graphqlUrl, {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ query: '{ posts(limit: 5, offset: 0, searchKey: "", sortOrder: "newest") { entities { _id title url } } }' })
+})
+.then(r => r.json())
+.then(d => console.log(JSON.stringify(d, null, 2)))
+.catch(console.error);
diff --git a/test_regex.js b/test_regex.js
new file mode 100644
index 00000000..bd52eb7e
--- /dev/null
+++ b/test_regex.js
@@ -0,0 +1,5 @@
+const fs = require('fs');
+let html = fs.readFileSync('client/index.html', 'utf8');
+const ogTitle = 'Test Title';
+html = html.replace(//, ``);
+console.log("Matched:", html.includes(ogTitle));
diff --git a/test_regex2.js b/test_regex2.js
new file mode 100644
index 00000000..7c604f82
--- /dev/null
+++ b/test_regex2.js
@@ -0,0 +1,16 @@
+const ogTitle = 'Replaced Title';
+const testCases = [
+ '',
+ '',
+ '',
+ '',
+];
+
+const regex = /]*property=["']?og:title["']?[^>]*>/i;
+
+testCases.forEach(html => {
+ const result = html.replace(regex, ``);
+ console.log("Original:", html);
+ console.log("Replaced:", result);
+ console.log("---");
+});