Skip to content

Commit 612f228

Browse files
authored
Merge pull request #162 from nulib/deploy/staging
Production push
2 parents 1d15a1c + 1a7c242 commit 612f228

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

src/api/response/iiif/collection.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,19 @@ function homepageUrl(pageInfo) {
102102
result = new URL(`/collections/${collectionId}`, dcUrl());
103103
} else {
104104
result = new URL("/search", dcUrl());
105-
if (pageInfo.options?.queryStringParameters?.query)
105+
if (pageInfo.options?.queryStringParameters?.query) {
106106
result.searchParams.set(
107107
"q",
108108
pageInfo.options.queryStringParameters.query
109109
);
110+
}
111+
112+
if (pageInfo.query_url.includes("similar")) {
113+
// Grab the work id from the query_url and add it to the search params
114+
const regex = /works\/(.*)\/similar/;
115+
const found = pageInfo.query_url.match(regex);
116+
result.searchParams.set("similar", found[1]);
117+
}
110118
}
111119

112120
return result;

src/helpers.js

+20-1
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,29 @@ const AcceptableHeaders = [
3737
"X-Forwarded-Port",
3838
"X-Requested-With",
3939
];
40+
41+
const ExposedHeaders = [
42+
"Cache-Control",
43+
"Content-Language",
44+
"Content-Length",
45+
"Content-Type",
46+
"Date",
47+
"ETag",
48+
"Expires",
49+
"Last-Modified",
50+
"Pragma",
51+
];
52+
4053
const TextTypes = new RegExp(/^(application\/(json|(.+\+)?xml)$|text\/)/);
4154

4255
function addCorsHeaders(event, response) {
4356
const allowOrigin = event?.headers?.origin || "*";
4457
const corsHeaders = {
4558
"Access-Control-Allow-Origin": allowOrigin,
4659
"Access-Control-Allow-Headers": AcceptableHeaders.join(", "),
47-
"Access-Control-Allow-Methods": "POST, GET, OPTIONS",
60+
"Access-Control-Allow-Methods": "POST, GET, HEAD, OPTIONS",
4861
"Access-Control-Allow-Credentials": "true",
62+
"Access-Control-Expose-Headers": ExposedHeaders.join(", "),
4963
"Access-Control-Max-Age": "600",
5064
};
5165
if (!response.headers) response.headers = {};
@@ -169,6 +183,11 @@ function normalizeHeaders(event) {
169183

170184
function baseUrl(event) {
171185
event = normalizeHeaders(event);
186+
187+
// For use with the local https-proxy in dev mode
188+
if (event.headers["x-forwarded-base"])
189+
return event.headers["x-forwarded-base"];
190+
172191
const scheme = event.headers["x-forwarded-proto"];
173192

174193
// The localhost check only matters in dev mode, but it's

test/unit/api/response/iiif/collection.test.js

+27
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,31 @@ describe("IIIF Collection response transformer", () => {
5454
expect(body.status).to.eq(404);
5555
expect(body.error).to.be.a("string");
5656
});
57+
58+
it("handles a request including /similar route", async () => {
59+
let pagerWorkSimilar = new Paginator(
60+
"http://dcapi.library.northwestern.edu/api/v2/",
61+
"works/1234/similar",
62+
["works"],
63+
{ query: { query_string: { query: "genre.label:architecture" } } },
64+
"iiif",
65+
{
66+
includeToken: false,
67+
queryStringParameters: {
68+
collectionLabel: "The collection label",
69+
collectionSummary: "The collection Summary",
70+
},
71+
}
72+
);
73+
74+
const response = {
75+
statusCode: 200,
76+
body: helpers.testFixture("mocks/search.json"),
77+
};
78+
const result = await transformer.transform(response, pagerWorkSimilar);
79+
expect(result.statusCode).to.eq(200);
80+
81+
const body = JSON.parse(result.body);
82+
expect(body.homepage[0].id).to.contain("search?similar=1234");
83+
});
5784
});

0 commit comments

Comments
 (0)