Skip to content

Commit

Permalink
Merge pull request #10 from discoverygarden/feature/cors-access
Browse files Browse the repository at this point in the history
MIR-12: CORS access and more flexible config
  • Loading branch information
nchiasson-dgi authored Jan 30, 2024
2 parents 743d2e5 + e818f97 commit ff33244
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ There are some environment variables to help integrate with IIIF Image APIs, in

Presently, we indicate `level2` compliance for each IIIF Image API endpoint.

As a point of convenience, it is possible to specify the `IIIF_IMAGE_V*_SLUG`
values using `base:`, as used by
[Drupal's `Url::fromUri()`](https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Url.php/function/Url%3A%3AfromUri/10).
For example, if you are using a proxy to make a `/iiif/2` path for a IIIF-I v2
endpoint, such that your slug would be
`https://{your hostname}/iiif/2/{identifier}`, then you can instead use
`base:/iiif/2/{identifier}` to configure the reference more explicitly relative
to the hostname used to access the site.

## Troubleshooting/Issues

Having problems or solved one? contact
Expand Down
6 changes: 5 additions & 1 deletion src/Controller/V3/ManifestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ public function build(string $parameter_name, RouteMatchInterface $route_match)
return (new JsonResponse(
$this->serializer->serialize($_entity, 'iiif-p-v3'),
200,
[],
[
'Access-Control-Allow-Credentials' => 'true',
'Access-Control-Allow-Origin' => '*',
'Access-Control-Allow-Methods' => 'GET',
],
TRUE
));
}
Expand Down
5 changes: 3 additions & 2 deletions src/EventSubscriber/V3/BaseImageBodyEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Drupal\iiif_presentation_api\EventSubscriber\V3;

use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\Core\Url;
use Drupal\file\FileInterface;
use Drupal\iiif_presentation_api\Event\V3\ImageBodyEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
Expand Down Expand Up @@ -75,13 +76,13 @@ protected function getBody(?string $slug, FileInterface $file, array $extra = []
'{identifier}' => rawurlencode($id_plugin->getIdentifier($file)),
]);
return [
'id' => "{$base_id}/full/{$size}/0/default.jpg",
'id' => Url::fromUri("{$base_id}/full/{$size}/0/default.jpg", ['absolute' => TRUE])->toString(),
'type' => 'Image',
'format' => 'image/jpeg',
'service' => [
[
// @todo Add in auth in some manner.
'id' => $base_id,
'id' => Url::fromUri($base_id, ['absolute' => TRUE])->toString(),
] + $extra,
],
];
Expand Down

0 comments on commit ff33244

Please sign in to comment.