Skip to content
Snippets Groups Projects
Commit b2905f9e authored by Tarje Lavik's avatar Tarje Lavik
Browse files

Fix domain error on collection API

parent e9cb2f24
No related branches found
No related tags found
No related merge requests found
import {sanityClient, previewClient} from '../../../lib/sanity.server' import {sanityClient, previewClient} from '../../../lib/sanity.server'
const getClient = (preview) => (preview ? previewClient : sanityClient) const getClient = (preview) => (preview ? previewClient : sanityClient)
const domain = process.env.VERCEL_URL ? `https://${process.env.VERCEL_URL}` : "http://localhost:3000"
/* /*
Construct a IIIF Presentation v3 collection json Construct a IIIF Presentation v3 collection json
*/ */
...@@ -26,11 +27,11 @@ export default async function handler(req, res) { ...@@ -26,11 +27,11 @@ export default async function handler(req, res) {
async function getObject(preview = false) { async function getObject(preview = false) {
const results = await getClient(id, preview).fetch(` const results = await getClient(id, preview).fetch(`
*[_id == $id][0] { *[_id == $id][0] {
"id": "http://localhost:3000/api/collection/" + _id, "id": "${domain}/api/collection/" + _id,
"type": "Collection", "type": "Collection",
label, label,
"items":*[_type == "HumanMadeObject" && ^._id in hasCurrentOwner[]._ref] { "items":*[_type == "HumanMadeObject" && ^._id in hasCurrentOwner[]._ref] {
"id": coalesce(subjectOfManifest, "http://localhost:3000/api/manifest/" + _id), "id": coalesce(subjectOfManifest, "${domain}/api/manifest/" + _id),
"type": "Manifest", "type": "Manifest",
label label
} }
......
import {sanityClient, previewClient} from '../../../lib/sanity.server' import {sanityClient, previewClient} from '../../../lib/sanity.server'
const getClient = (preview) => (preview ? previewClient : sanityClient) const getClient = (preview) => (preview ? previewClient : sanityClient)
const domain = process.env.VERCEL_URL ? `https://${process.env.VERCEL_URL}` : "http://localhost:3000"
/* /*
Construct a IIIF Presentation v3 collection json Construct a IIIF Presentation v3 collection json
*/ */
...@@ -40,7 +41,7 @@ export default async function handler(req, res) { ...@@ -40,7 +41,7 @@ export default async function handler(req, res) {
async function getObject(preview = false) { async function getObject(preview = false) {
const results = await getClient(preview).fetch(` const results = await getClient(preview).fetch(`
*[_type == "Group" && count(*[_type == "HumanMadeObject" && ^._id in hasCurrentOwner[]._ref]) > 0] { *[_type == "Group" && count(*[_type == "HumanMadeObject" && ^._id in hasCurrentOwner[]._ref]) > 0] {
"id": "http://localhost:3000/api/collection/" + _id, "id": "${domain}/api/collection/" + _id,
"type": "Collection", "type": "Collection",
label, label,
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment