Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions packages/endpoint-image/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ To customise the behaviour of this plug-in, add `@indiekit/endpoint-image` to yo

## Options

| Option | Type | Description |
| :---------- | :--------- | :----------------------------------------------------------------- |
| `cache` | `Function` | [Keyv store](https://github.com/lukechilds/keyv). |
| `me` | `string` | Publication URL. Used as prefix to image paths. |
| `mountPath` | `string` | Path to image resizing endpoint. _Optional_, defaults to `/image`. |
| Option | Type | Description |
| :---------- | :--------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `cache` | `Function` | [Keyv store](https://github.com/lukechilds/keyv). |
| `domains` | `Array` | List of domains to allow remote image resizing for. _Optional_, defaults to the [value provided for `publication.me`.](https://getindiekit.com/configuration/publication#me) |
| `me` | `string` | Publication URL. Used as prefix to image paths. |
| `mountPath` | `string` | Path to image resizing endpoint. _Optional_, defaults to `/image`. |
13 changes: 10 additions & 3 deletions packages/endpoint-image/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import {
createIPXNodeServer,
} from "ipx";

const defaults = { mountPath: "/image" };
const defaults = { domains: [], mountPath: "/image" };
const router = express.Router();

export default class ImageEndpoint {
name = "Image resizing endpoint";

constructor(options = {}) {
this.options = { ...defaults, ...options };
this.domains = this.options.domains;
this.mountPath = this.options.mountPath;
}

Expand All @@ -23,9 +24,15 @@ export default class ImageEndpoint {
}

_routes(indiekitConfig) {
const domains = Array.isArray(this.domains) ? this.domains : [this.domains];

const ipx = createIPX({
storage: ipxFSStorage({ dir: "./public" }),
httpStorage: ipxHttpStorage({ domains: indiekitConfig.publication.me }),
storage: ipxFSStorage({
dir: "./public",
}),
httpStorage: ipxHttpStorage({
domains: [indiekitConfig.publication.me, ...domains],
}),
});

router.use(createIPXNodeServer(ipx));
Expand Down
Loading